473,756 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple guide to using PyInstaller

true911m
92 New Member
This is a simple walkthrough to get PyInstaller up and running.

I decided to give PI a try, because it claims to be more selective about what it bundles into its executable files by default, and it also integrates UPX (Ultimate Packer for eXecutables) into the build process, if you have it installed. It also claims functionality on linux, as a bonus (I didn't test this). I highly recommend the UPX options, and will cover how to get it working on Windows.

At the time of this writing, the latest stable version of PyInstaller is 1.3, and UPX is 2.03.

The result here will be to convert a simple python app into a single .exe file that can be copied and run on any Windows XP machine. It may work on many other Windows platforms (and linux), but I haven't tested it.

You'll need a working Python installation before you continue. PyInstaller claims compatibility with versions 1.5 through 2.4. I'm running 2.5, and it's working just fine.

You can download PyInstaller from SourceForge at http://www.pyinstaller.org/.

PyInstaller does not install under Python's site-packages directory as most libraries do. Instead, you can put the contents of its directory (what you see when you unzip the download file) wherever you wish, but remember that you will either have to type its location or alter your system paths for the build process to work properly, so try to keep it relatively short. I haven't even tried the paths option, so if you try it and it works, drop a note here. My install location is c:\python25\pyi nstaller13, which means I took all those files from the archive folder and simply copied them to the install folder. Make a note of this path, because you'll have to substitute yours if it's different.

PyInstaller needs to be configured. Since it's compatible with all those Python versions, it needs to know which one it's working with. It's simple, though -- open the directory where you just copied those files, and double-click on Configure.py. PI will scan your Python install dirs, and make a config.dat file that customizes it for your installation.

Next, go ahead and download UPX from http://upx.sourceforge.net/#download . (I'm using the Win32 Console package). For the purposes of PyInstaller, you only need one file, upx.exe, placed in your system path. After unpacking the archive, copy upx.exe to your c:\pythonXX directory. That's all there is to it.

I'm starting with a basic Hello World app that I used in my prior walkthrough:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python 
  2. for i in xrange(10000): 
  3.     print "Hello, World!"
Create this with your favorite editor and save it as HelloWorld.py. Next, create a batch file to run the build process. Remember that path where you copied PyInstall? You'll need that here, on the first line below. Back to your editor to type the following:

Expand|Select|Wrap|Line Numbers
  1. set PIP=c:\python25\pyInstaller13\
  2. python %PIP%Makespec.py --onefile --console --upx --tk HelloWorld.py
  3. python %PIP%Build.py HelloWorld.spec
You can use whatever naming convention you wish, but because this may vary for each project, I'm saving it as HelloWorld.bat, right next to my HelloWorld.py file. See the notes at the end for the basics regarding those command-line options.

You should now have two files, HelloWorld.py and HelloWorld.bat, both in the same directory.

Double-click on HelloWorld.bat and sit back. Depending on your hardware, it could take from a couple seconds to a minute to complete. It seems to take a bit longer than the comparable py2exe build I described recently, and the UPX compression usually seems to add the most time, but this example should be pretty quick.

When the cmd window finishes, check the directory where you stored the two files. You should now see a new directory (buildHelloWorld) and a few new files (HelloWorld.spec, warnHelloWorld. txt, and HelloWorld.exe). The build directory and the .spec file were used by PyInstaller, and can be deleted. the warnXXX.txt file contains warnings; it seems these are always here, but so far they don't affect the program at all. And the .exe file is ready to go.

If you saw my py2exe walkthrough, you may remember that HelloWorld.exe topped out at 3.2MB from my 110-byte source file. This one weighs in at 1.5MB, a considerable improvement. In larger projects, where external .dlls and other resources are bundled into your project, the differences should be even more significant.

Go ahead, double-click on HelloWorld.exe, I know you want to...

Copy HelloWorld.exe to another computer (without Python on it), and run it there, just to see that it really works.

A few notes:

Just like py2exe, PyInstaller bundled a python interpreter, any required DLLs, and any referenced libraries in its output file, turning 100 bytes into 1.5MB. However, this is much smaller than the 3.2MB results from py2exe.

When you create HelloWorld.bat, above, you want to make a couple of simple choices based on each program you're 'compiling'. Here's the quick summary:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4.     --tk        This is required for inclusion of the tcl/Tk
  5.             libraries.  Unlike py2exe, PyInstaller doesn't 
  6.             recognized that this is used and include it
  7.             automatically.  However, you can leave it in
  8.             without doing any harm (as we did in this
  9.             example).  It adds some overhead, but the size
  10.             seems to vary.
  11.  
  12.     --upx        I mentioned that this is a great option, and 
  13.             it is, but it's really slow, especially as your
  14.             source file gets bigger.  It's a great option
  15.             for your final compile before distributing, but
  16.             you might save a lot of time if you turn it off
  17.             until then.
  18.  
  19.     --console    This is the DOS-like box, and carries the same
  20.     --noconsole    significance as the python vs. pythonw usage 
  21.             for your other programs.  If your program runs
  22.             in Windows and you've finished troubleshooting,
  23.             you probably want --noconsole.
  24.  
More info is available at www.pyinstaller .org, including some not-too-lengthy documentation pages.

Cheers,

- Mark
Dec 21 '06 #1
10 110289
bartonc
6,596 Recognized Expert Expert
I like your style, Mark. This is great info and I can see that you have gone to some trouble to get it to our members. I also see that you are now linking threads. This is awesome member partisipation! Thank you so much.
I made this one sticky, so here is a link back to the py2exe thread.
Dec 21 '06 #2
naamakat
1 New Member
How can I pack a more complicated structure of files ? any project have several directories - how can I manage a Tree of files ?

thanks ..
Jan 23 '08 #3
dayneKnight
1 New Member
Excellent guide Mark! Really easy to follow and it actually worked. You saved me a lot of time in a project I'm working on. Thanks very much!

Since you obviously have a skill with explaining complex topics clearly, I hope you'll consider posting a few more guides.
Jul 21 '08 #4
shadowlink
1 New Member
Hey, I've been trying to get pyInstaller to work but i'm getting the following problems.
Can someone help me out with this?


(warnHelloWorld .txt)
W: no module named posix (conditional import by os)
W: no module named pwd (delayed, conditional import by posixpath)
W: no module named win32api (delayed import by iu)
W: no module named posix (delayed, conditional import by iu)
W: no module named org (top-level import by copy)
W: no module named _emx_link (conditional import by os)
W: delayed __import__ hack detected at line 0 - encodings (C:\Python25\li b\encodings\__i nit__.pyc)
W: delayed eval hack detected at line 0 - os (C:\Python25\li b\os.pyc)
W: delayed conditional exec statement detected at line 0 - iu (c:\python25\py Installer1.3\iu .pyc)
W: delayed conditional exec statement detected at line 0 - iu (c:\python25\py Installer1.3\iu .pyc)
Jul 22 '08 #5
dbpeckham
3 New Member
The instructions are great but they did not work for me. Here is what I see when I run the HelloWorld.bat file:

c:\Python25\Scr ipts>python c:\python25\pyI nstaller13\Buil d.py HelloWorld.spec 'python' is not recognized as an internal or external command, operable program or batch file

I get the "'python' is not recognized..." note when I enter the word 'python' before any .py script.

Any ideas?
Don
Nov 16 '08 #6
GeertVc
1 New Member
@dbpeckham
1 reason, 2 solutions:

1. the directory where python.exe resides, is not part of your PATH variable

1. add the directory where python.exe resides, to your PATH environment variable
2. prefix "python" in the batch file with the complete path

That should solve your issue.

Best rgds,
--Geert
Feb 12 '09 #7
dbpeckham
3 New Member
I gave up on pyInstaller several months ago but I'm trying again.

I copied the upx.exe file to c:/python25/

I ran c:/python25/pyInstaller-1.3/Configure.py and got the following response:

I: Finding TCL/TK...
I: found TCL/TK version 8.4
I: testing for Zlib...
I: ... Zlib available
I: Testing for ability to set icons, version resources...
I: ... resource update available
I: Testing for Unicode support...
I: ... Unicode available
I: testing for UPX...
I: ...UPX unavailable
I: computing PYZ dependencies...

I ran HelloWorld.bat and got the following response:

..."You must run Configure.py before building!"
SyntaxError: invalid syntax

Any suggestions?
Jun 17 '09 #8
dbpeckham
3 New Member
PS: I am using Windows Vista.
dbpeckham
Jun 17 '09 #9
Stef le Breton
2 New Member
Hi,


I'm also very interested having more information on how to compile a more structures projects with different directories with lib imported in the higher script and empty __init__.py files

Could you help ?
Apr 20 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1523
by: Frank Millman | last post by:
Hi all From time to time there is a request for a simple way of storing and accessing data without using a full SQL database. I had this requirement recently, and I was pleasantly surprised by how much I could achieve with a simple Python list and list comprehensions. Assume the need to store data consisting of first name, surname and
0
1786
by: Joh | last post by:
hello, i've readed "Charming Python: Generator-based state machines" www-106.ibm.com/developerworks/ linux/library/l-pygen.html , but i still can not get the point on how using generator for FSM i'm interested in a very simple FSM which would be able to recognize consecutive sequence of texts, please can someone give me a hint on how to do this using yield ?
6
4964
by: hoover_richard | last post by:
I am a newbie to C++ and I need help with a simple program I am trying to write. My program is designed to print all of the odd integers contained in an array and output the sum of the odd integers. My code is listed below, but the problem is that my output of sum is wrong. For example, I am using 1347830 for my integers and the program outputs 373 and after adding 373 you should get 13 for the total, but that doesn't happen. Any help...
7
5077
by: bfowlkes | last post by:
Hi, I am new to the C programming language and programming in general. I am writing a simple roulette program. I have everything working so far but it seems a little plain. What I would like to do, but I have no idea how to do, would be to create a simple animation each time the roulette wheel is spun. Something like this. 1 2 3 4 5 6 7 8 9 10 11
1
3661
by: kbperry | last post by:
Hi all, I am pretty confused on this? While pyinstaller has a "MakeCOMServer.py" thing, it seems to blow up every time I run it. It keeps complaining that a dictionary that I have has "TypeError: unscriptable object.", but when I run my code normally (outside of trying to make an .exe), it runs perfectly. The dictionary doesn't have any data in it, until I call a method to grab some data from a file.
4
34892
true911m
by: true911m | last post by:
Here's a little walkthrough to get py2exe up and running. I'm not an expert, so I can't help much with any problems you might have. This is what worked for me. The result here will be to convert a simple python app into a single .exe file that can be copied and run on any Windows XP machine. It may work on many other Windows platforms, but I haven't tested it. You'll need a working Python installation first, preferably v2.3 or later. ...
1
2127
by: psbasha | last post by:
Hi, Is it possible to create a simple viewer using Tkinter Modueles?. If not ,is it possible thru Python and OpenGL or anyother ways of creating a simple viewer?. I would like to have the following options ( Zoom,Pan,Rotate etc),with Graphical display. Thanks
5
1733
by: SM | last post by:
Hello I have simple question using simpleXML and PHP. i have an xml file that looks like this: <?xml version="1.0" encoding="UTF-8"?> <discography version="0.01"> <CD> <title>Moonlight</title> <year>1978</year>
0
2493
by: asoft | last post by:
Please i need help with this. I just started using python and i hace run into several issues. The on that i can't tackle is the issue of no being able to compile the python code using PyQt4 application It gives the error ImportError: cannot import name QtCore. .. I tries the trunk from the snv, but it still gives the same error. I also would like to know. if there are any report generation tool i can use with python similar to crystal...
0
9431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9255
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3780
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.