Reputation: 539
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.
Upvotes: 3
Views: 2685
Reputation: 4664
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.
Upvotes: 0
Reputation: 823
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
Upvotes: 0