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.
Related
Problem: I get the error "ModuleNotFoundError: No module named 'pydicom'" when trying to run an executable created from a python program using cx_Freeze.
Background: I am using Python 3.8 with Anaconda 2020.02 on Windows 10 with PyCharm 2019.3.3 Community Edition as an editor, cx_Freeeze version 6.2, pydicom version 2.00. I am new to Python programming.
I had some initial trouble installing pydicom (pydicom-2.0.0-pyh9f0ad1d_0) and needed to go through the Anaconda Navigator to get it installed properly. Pydicom is not included with the standard package apparently.
Attempted: There are a lot of posts describing similar problems. I tried the following code for my setup.py but still no luck
from cx_Freeze import setup, Executable
packages = ['pydicom']
include_files = ["C:/<me>/.conda/pkgs/pydicom-2.0.0-pyh9f0ad1d_0/site-packages/pydicom"]
setup(name="MyProgram",
options={"build.exe": {'packages':packages, 'include_files':include_files}},
executables = [Executable("MyProgram.py")])
I fooled around with the include_files variable (e.g., ""C://.conda/pkgs/pydicom-2.0.0-pyh9f0ad1d_0/site-packages") with no luck.
I also use pandas in this code but there are no complaints when running (maybe it failed before executing any pandas code?)
Any suggestions welcome!
Thanks,
Tom
When I ran the example code using scikit-surprise which is a package in python, it showed that "cannot import name similarities".
My operating system is windows 10 and python version is 2.7. When I tried to ran the exactly the same code on the school computer, it succeeded. The operating system in school computer is also windows 10. So it's not the problem of operating system.
I am very confused about what happened. When I commented out the "from .. import similarities as sims", there is another import error "Import Error: No module named optimize_baselines".
When I checked what was .optimize_baselines and similarities, I found they were all .c files.
So it seems that it cannot correctly import .c files. But how to deal with that?
You see import error as those packages are not installed in your home computer. So if those are public packages then you can download it via pip or easy_install.
I solved this problem by installing python3. I installed python2 using anaconda and failed to run the system. I found that the same situation happened on my school computer that the system cannot run with python2 but succeed using python3. I am sorry that I just found I typed "scikit learn" . It should be "scikit surpirse" which is a recommendation system. I guessed the problem was because the C++ compiler. But I am not sure about that.
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 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.
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