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.
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 have built a tkinter GUI for survey entry in python3.4 that uses a number of packages. I then need to compile it to an executable so that I can put it on a coworkers machine (we both are on windows7 platform) I've structured my setup.py to look like:
from cx_Freeze import setup, Executable
import sys
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name='Survey Entry',
version='3.5',
license='MIT',
description='GUI For entering survey data',
executables= [Executable("Survey Entry.py", base=base)],
options={"build_exe":{"packages":['tkinter','cx_Oracle','datetime','time','enter_survey','lookup',
'queryfuncs','login','gui', 'datetime', 'add_respondent', 'possible_matches']}}
)
This worked absolutely fine for tons of versions. But then I added a functionality that uses fuzzywuzzy to compare strings. When I include that and add fuzzywuzzy to the packages list in the options dictionary and compile it, I get a big error when I try to run the exe that ends with ImportError: No module named 'Levenshtein'
I don't understand because in my development the module works fine. I've tried to include Levenshtein in the setup but it doesn't exist as a module. I don't have python-Levenshtein installed though because I can't get the .whl to install on my windows machine.
Has anyone ran into this? Why would fuzzywuzzy cause this error when it runs fine through python? Is there something I'm missing?
The complete error can be seen here: http://imgur.com/a/rSKsS
EDIT: I was able to figure it out - I need the python-Levenshtein module installed, had to keep working at it to get the .whl to install (apparently I'm not as proficient with the command prompt as I wanted to believe). After that I included Levenshtein and fuzzywuzzy in the packages list and it compiled without error.
I'm going to leave this up because I couldn't find this on a google search so hopefully no one else falls victim!
Found the solution - python-Levenshtein needs to be installed. Got mine from gohlke's repository: http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-levenshtein - make sure you have the platform that matches your python installation! I run a x64 windows but I use x32 python for compatibility with my Oracle driver - so I needed to install the 32-bit module.
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 spent the last 2 hours searching the web to find very little and nothing that helps.
Hoping someone here will be able to help me.
When using cx_Freeze to convert my .py file to a .exe files, I get an error stating no module named xlsxwriter can be found.
When this module is removed from the packages list the program compiles with no problem.
My code:
import cx_Freeze
Executables = [cx_Freeze.Executable("test.py")]
cx_Freeze.setup(
name="Sort PLL Bale Lists",
options={"build_exe": {"packages":['xlrd','xlsxwriter']}},
executables = Executables
)
Try adding includes list to your code eg: includes = [xlrd,xlsxwriter]. Refer to this SO post for help. If the error persists try installing xlrdwriter with pip install xlsxwriter.
There is a chance that you have xlrd already installed and you have not installed xlsxwriter. This can be verified with pip freeze. pip freeze will provide a list of installed packages.
I have a Python program that I am attempting to package using Py2Exe. I am using Python 3.4. My program uses Sqlachemy and Sqlite3 in order to create and access the database.
When I install the resulting files from Py2Exe I get the dll error:
Sqlite is not a valid Win32 application
I have attempted to go through the various work-arounds listed here, including uninstall python and re-installing all modules to ensure that I have only the 32 bit versions. Any ideas?
My setup.py code is listed below. It uses some of the work arounds listed for sqlite, as well as a number for sqlalchemy
from distutils.core import setup
import py2exe
setup(console = ['notetest.py'],
options = {'py2exe' : {'packages' : [
'reportlab',
'reportlab.graphics.charts',
'reportlab.graphics.samples',
'reportlab.graphics.widgets',
'reportlab.graphics.barcode',
'reportlab.graphics',
'reportlab.lib',
'reportlab.pdfbase',
'reportlab.pdfgen',
'reportlab.platypus',
'sqlalchemy.dialects.sqlite',
#'sqlalchemy.databases.sqlite',
'sqlite3'
]}} )
Ok, so i'm not sure if this is a truly "valid" work around, but it works and is rather simple.
I downloaded the most recent Sqlite dll from Sqlite. I simply replaced the Py2Exe generated Sqlite dll with this updated file and the program worked perfectly.
I am also using InnoSetup to compile an MSI installer, so one can simply copy the "newer" dll into the pre-compiled directory for inclusion into the MSI installer.
This worked for me. hope it helps others