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.
Related
I have been building an application on Linux using python pygobject, and now I need to distribute it on Windows.
I first installed pygobject via msys2 (as per the official pygobject documentation)
Now, using msys2/mingw32, I can run my program typing
python3 main.py
But when I try to freeze it into a .exe with Pyinstaller, and try to run the produced .exe
If I Don't use --onefile, I get an import error on the _struct module (whereas "import _struct" works in python shell)
If I use --onefile, I get the Following error :
error:
lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-ani.dll could not be extracted!
fopen: No such file or directory
I’m using the devel version of Pyinstaller. I know next to nothing on Windows OS… does anyone know how to fix that error ?
It sounds like you were on the right path, unfortunately you ran in to a bug in PyInstaller. The good news is that the issue with the No module named '_struct' error is now fixed and released in version 3.6 and later. I would recommend using the --onedir mode of PyInstaller, you should be able to successfully package a GTK app for Windows.
I am trying to create a standalone executable with my python script using cx_Freeze.
This is the error I am getting: error: [Errno 2] No such file or directory: 'C:\\Program Files\\Python37\\tcl\\tcl8.6'
Does this have anything to do with using a module such as PySimpleGUI? I am using PySimpleGUI 3.1.2.
How do I fix this?
Here is my code (setup.py and Track_Companion.py).
Note: Track_Companion.py is not yet finished.
Instructions for making .EXE files from programs using PySimpleGUI can be found in the docs here.
To create the .EXE:
pyinstaller -wF yoursourcefile.py
I would upgrade your PySimpleGUI package prior to doing it.
cx_Freeze does not yet support Python 3.7, it has a bug. A bugfix exists but has not yet been released, however you can apply it manually, see What could be the reason for fatal python error:initfsencoding:unable to load the file system codec? and Cx_freeze crashing Python3.7.0. Or you can rollback to Python 3.6 if this is an option for you.
Have you checked that C:\\Program Files\\Python37\\tcl\\tcl8.6 exists? It would anyway be better to let your setup script dynamically determine you Python installation directory using PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__)) as done in this answer.
You need to tell cx_Freeze to include the Tcl and Tk DLLs using the build_exe option include_files as done in the same answer; if you are using cx_Freeze 5.1.1 or 5.1.0, you need to do it slightly differently, see this answer.
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.
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.
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',
],
},
...
)