Py2Exe, Sqlite - Not a valid Win 32 Application - python

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

Related

how to build .exe for python 3.5+, 3.6 if possible?

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.

cx_Freeze giving error when using fuzzywuzzy

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.

py2exe exe closes immediately after launch

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.

python3 & pyqt4 & cx_freeze: no module named 'sip'

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.

py2exe throws ImportError: DLL load failed: The specified module could not be found

I cannot seem to get py2exe to work properly. I have run "python setup.py py2exe" in cmd, as well as "python setup.py install"... and When I try to run my executable setup, I get this same error over and over:
After a week I'm starting to get quite frustrated and I'm hoping to be able to resolve the issue today.
I'm using Python 2.7 and py2exe v0.6.9. 64-bit Windows7
FINALLY, I can die a happy man. After agonizing over this problem for over a week, I figured out that the issue is that I had to download the 64bit version of py2exe from SourceForge. The "Get Latest Version" link that they have at the top is for Python 2.5, which is very misleading because I would have assumed it would at least use the latest version of PYTHON that it supports, which I believe is the version I have, Python 2.7.1.
I had to go into the "Browse All Files" section and manually navigate to v0.6.9 and then pick the appropriate version.
I am now able to create an executable from running "C:\Python27\setup.py py2exe".
thanks all for your help/replies.
The most important lines in that error are the last two -
import py2exe_util
ImportError: DLL load failed: The specified module could not be found.
That means py2exe was not installed completely in the first place. Try re-installing it.
You need a version of py2exe that matches the architecture of your python install.
If you have a 32bit python install you need a win32 py2exe installer.
If you have a x64 python install you need a win64 py2exe installer.
In my case I am on a 64bit machine with a 32bit python install. The Source Forge 'latest' link gave the win64 version of py2exe (because it detected my machine type). But it didn't work, I kept getting the following error:
ImportError: DLL load failed with error code 193
I needed to go back to Source Forge and 'Browse all files' to find the win32 version.
I'm not sure my problem is the same as OPs, but since I found this thread while searching for a solution to my problem, I'll add what I found.
My issue was building 32 bit program on a 64 bit machine. The exe worked fine on other 64 bit machines, but raised the DLL load failed: The specified module could not be found error on other 32 bit machines.
What I ended up figuring out was that py2exe was including windows DLLs that it shouldn't have been in the package. When these DLLs were removed, the error went away.
py2exe has an option to explicitly exclude dlls. Here's a snippet of what worked for me:
setup(
...
options={
'bdist_esky': {
'freezer_module': 'py2exe',
'freezer_options': {
'dll_excludes': [
'CRYPT32.dll',
'IPHLPAPI.DLL',
'MPR.dll',
'MSWSOCK.dll',
'PSAPI.DLL',
'WTSAPI32.dll',
],
},
...
)

Categories