How can I convert my python program with Qt for GUI to .exe file??
I want to make an installation file for my python source code
First part : "How can I convert my python program with Qt for GUI to .exe file??"
You can use PyInstaller, which supports python 2.2 - 2.7 and it has a hook system for including Qt with all dlls and plugins.
You can use also :
bbfreeze
cxfreeze
py2exe (pretty old)
esky (a wrapper of all the above except PyInstaller)
Basically all this systems have a definition file to handle and produce the binary package. For instance, esky has a setup.py (which is a distutil file) to produce the package :
from esky import bdist_esky
from distutils.core import setup
setup(name="appname",
version="1.2.3",
scripts=["appname/script1.py","appname/gui/script2.pyw"],
options={"bdist_esky":{"includes":["mylib"]}},
)
Than you can call "python setup.py bdist_esky"
For PyInstaller the thing is pretty different. From console, cd in PyInstaller folder :
python Makespec.py [options] script.py
This produce a spec file with all the options to package your script. You can also modify this file with an editor.
python Build.py script.spec
This analyzes and builds your exe (or os binary equivalent).
Second part : "I want to make an installation file for my python source code"
You have to use NSIS, InnoSetup, BitRock Installer, IzPack or equivalent to produce a platform installer. So you have to take the binary result produced on the first part and package it for os distribution. Almost all the installer systems are thought for Windows systems.
Cross platform : Zero Install, IzPack ...
If you use IzPack you can have a cross platform installer paying the price of including a jvm.
Using Py2Exe is the most suitable choice here.
PY2EXE Binaries :http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/
Usage :
Create a new setup python file:
from distutils.core import setup
import py2exe
setup(console=['Your python script absolute path'])
Save this file.
Goto Command Prompt and change directory where the setup.py file is saved.
Run the command :
[python <your python script name_to be converted in exe> py2exe]
I cannot post the images as I don't have 10 reputations to post more than two links. Please comment if any help required.
Related
Is there now an easy protocol to build a .exe from python 3.5+, using modules pyqtgraph, qt5, theano, pymc3, numpy, scipy, os and sys, and opening a simple GUI stored in a '.ui' file ? I lost hours and eventually failed to make one (for w7-64 bits). Help !
preliminary failure with py2exe: I first install py2exe for python 3 but it turns out this is not compatible with my python 3.6 yet, so I downgraded to python 3.5… to get a bunch of errors. Then I went to forums and tried the proposed cures but failed (I’m uneasy with windows), the alternative being to downgrade to python 3.4… So I downgraded to python 3.4 to get an error concerning a missing ‘msvcr100.dll’ that I tried to install following instructions on forums but by default I don’t have the permission to modify system directories… When I eventually had this permission it turns out the ‘regsvr32’ command fails (isn’t this for 32 bits ? but there is no ‘regsvr64’…). Following episodes are described below.
update august 23, 2017, 1pm:
I also tried pyinstaller as advised but it failed (see my related question build a .exe for Windows from a python 3 script importing theano with pyinstaller)
I also tried cx_freeze but it failed (see my related question build a .exe for Windows from a python 3 script)
I also tried pynsist but it fails (same link than above)
what's next ?
update september, 2, 2pm:
I eventually managed to build a .exe with pyinstaller after many episodes.
Unfortunately I failed to deal with the ‘theano’ module (that is required in my case by the ‘pymc3’ module) and I had to modify the .py files and give up part of the application. Could anyone help me building a .exe for windows 7+, with the ‘theano’ module ?
see build a .exe for Windows from a python 3 script importing theano with pyinstaller
Pyinstaller Works with Python 3.5 and it is working even for packages like tensor-flow, scipy , etc (The packages I worked with)
py -3.5 pip install pyinstaller
then go the C:\Users\user\AppData\Local\Programs\Python\Python35\Scripts
and run the command
pyinstaller <code .py file along with directory> --onefile
--onefile : is for compressing the build and get a single file as output
I would suggest pyinstaller see http://www.pyinstaller.org/
The pyinstaller already supports 3.5
The development version supports 3.6
It is better to use spec file to import other hidden libraries. I listed all Sklearn libraries and add them to spec file as a hiddenimports, you can add libraries you used in your project.
I'm incredibly new, and I was wondering if I could package colorama with cx_freeze, I've seen some people with a similar question yet I completely do not understand how to specifically choose colorama. Please, explain like I'm 10 years old. This is the coding in my setup.py file for cx_freeze:
from cx_Freeze import setup, Executable``
setup(name = "popcarventure" ,
version = "0.1" ,
description = "" ,
executables = [Executable("TheAdventure.py")])
Can you please post how to specifically import colorama? Much appreciated!
Note: I am using python 3.4 on windows, not python 2.
I recently started in python too and came across the same problem, aparently the latest version of cxfreeze has difficulties to include compressed modules (.egg, they are similar to .zip files).
So I'm going to try to explain in the easiest way I can, how I managed to get this working.
I assume you installed Python in C:\Python34.
Close any python command line or IDLE GUI.
Go to your Python34 installation folder, it should be on C:\Python34.
Once there open the "Lib" folder and locate "site-packages" folder
Now you need to delete your colorama egg file, this is the file that contains the module it is called colorama-0.3.3.egg or something similar, we need to install it uncompressed.
Create a .cfg file with the instruction to uncompress these egg files during the installation, go to C:\Python34\Lib\distutils create a new notepad file and name it: distutils.cfg and paste this:
[easy_install]zip_ok = 0
Save it and continue with the last step
Open a windows command prompt, write:
cd C:\python34\scripts
Now you simply write:
pip install colorama
Once it finishes you can start creating executables with colorama on it
NOTE: From now on any egg module you install with pip or easy_install or python install commands, will be uncompressed, so with cx_freeze they will work.
I have a python (2.7) code that has a gui (Tkinter) and another module. I've tried to make it an .exe file but had strange results. Below are the two cases:
No module named py2exe: I use Canopy 64bit for making python scripts. Since it is 64 bit, I downloaded the 64 bit version of py2exe for python 2.7 and installed. During install, py2exe installer automatically sees my canopy path and I check if I have py2exe module after installation. I checked and saw that py2exe folder and module was in Canopy/Libs. So it looked like it was installed correctly but when I go to cmd, change dir, and then python myscript.py py2exe, it says no module named py2exe. If I start 64 bit IDLE and import py2exe, it imports.
So I tried installing the 32 bit version of py2exe. During installation it sees C:/Python27 so I install it there, 64 bit IDLE can't import if I call py2exe, but 32 bit can. With the 32 bit version of py2exe when I do python myscript.py py2exe, it compiles my script to an .exe file. However, when I double click the .exe file a cmd window opens and closes immediately after launch.
I've checked other similar topics here but none helped me with this, since it is weird that 64 bit installation gives no module named py2exe. Any help would be appreciated, thanks in advance.
Note: I have C:/Python27 in my system variables path and Canopy's path in my user variables path.
Update to Case 1: When I start canopy command prompt and cd from there, and then follow the typical steps, py2exe starts to run but gets stuck at: MSVCP90.dll: No such file or directory and it exits
Update: Turns out it is about my imports. Problem only occurs when I import matplotlib. With Tkinter, xlrd and numpy imported, it works without a problem but when I import matplotlib, it gives me that error about msvcp90.dll. If I delete all matplotlib imports from my gui, it compiles but when I try to start the .exe it starts a cmd window which immediately closes right after.
AFAIK, py2exe leaves some DLLs behind. They should be copied manually into your dist directory. I would suggest running your compilation through Dependency Walker to find out what Dlls are missing.
http://www.dependencywalker.com/
5.2. Python 2.6, 2.7, 3.0, 3.1
For Python 2.6, the DLL you need is called MSVCR90.dll. Py2exe is not
able to automatically include this DLL in your dist directory, so you
must provide it yourself.
To complicate things, there is more than one version of this DLL in
existance, each with the same filename. You need the same version that
the Python interpreter was compiled with, which is version
9.0.21022.8. Through the remainder of these instructions, hover your mouse over the dll file (or the vcredist_x86.exe installer executable)
to confirm which version you've got. You'll need the vcredist_x86.exe
that contains the Microsoft Visual C++ 2008 Redistributable Package
published 29-11-2007, so not the VS2008 SP1 one (tested with Python
2.7.1).
http://www.py2exe.org/index.cgi/Tutorial
Try using the 'setup.py' code below. You exclude the dll file that causes the error and you also have to import the sip module.
from distutils.core import setup
import py2exe
setup(console=['hello.py'],
options = {
"py2exe": {
"dll_excludes": ["MSVCP90.dll"],
"includes":["sip"]
}
},
)
In order to see what's the problem, run your exe file from terminal.
I'm trying to build PySVN from source on my Windows 7 PC. It's running 64bit Windows, but for various reasons I need to compile it so that it works on 32bit Python. That's what we run on a lot of our automation servers.
I've downloaded the PySvn extensions source, I've got Visual Studio 2008 Express Edition installed. I've tried to a batch to automate the process, it looks like this:
set PROJECT_DIR=%~dp0
set SRC_DIR=%PROJECT_DIR%pysvn-1.7.8
cd %SRC_DIR%\Builder
set SVN_VER_MAJ_MIN=1.8
call builder_custom_init.cmd
cd %SRC_DIR%\Source
python setup.py configure --platform=win32
When I get to the last line I get the error message:
Info: Configure for python 2.7.6 in exec_prefix c:\python27
('Error:', 'cannot find PyCXX include CXX/Version.hxx - use --pycxx-dir')
My python - include directory does not contain a file called Version.hxx. Where do I get this file, how do I fix this bug?
One way is to install PYCXX by hand - it installs a Version.hxx under the Include folder on windows.
The source for PYCXX is here: http://cxx.sourceforge.net/
Another way is to point the C/L parameter --pycxx-dir at the Import folder under the pysvn root where the corresponding version of PYCXX for the version of pysvn is kept.
(On top of this you will have to build the subversion libraries on windows.)
I just recently learned some python & pyqt basics, and today i wanted to convert a program I made to exe. I'm using python 3.4.1 and PyQt4 installed via binary installer (my system is 32-bit Windows 7 Enterprise, if it makes any difference). So I found Cx_Freeze should be a viable tool for the job, but as for now, I have spent several hours trying to make it work.
I installed Cx_Freeze from this site (after installing it from pypi.python.org and getting some error considering modules; this version supposedly has a patch that fixed it), and this is (the current version of) my setup.py file:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["re", "sip"]}
setup(
name = "Project",
version = "1.0",
description = "desc",
options = {'build_exe': build_exe_options},
executables = [Executable("project.py", base = "Win32GUI")]
)
So, when i run it in cmd (python setup.py build), it creates the build folder and everything, but when i try to run the project.exe inside I get this error message.
Among other, I also had tried having "re" and "sip" in includes (instead of packages). Also one of earlier versions had no specific options defined by me. Also tried simply copying several other setup files I could find on the net, and so on - yet nothing worked.
Thanks in advance for any help :))
Reposting as an answer:
This is a bug that will be fixed in the next version of cx_Freeze. When it can't parse a code file as Python syntax, it tries to treat it as a compiled library, but that's not necessarily true (e.g. PyQt includes some separate files for Python 2 and 3). In the meantime, the simplest way to work around it is to apply the fix manually to your installed cx_Freeze, as described in this comment.