3

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:

  1. 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.

  2. 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.

Deniz
  • 509
  • 7
  • 26
  • Maybe related to [No module named py2exe](https://stackoverflow.com/questions/9559601/no-module-named-py2exe?rq=1). See that and tell us what is your version of py2exe package? – smci Jun 07 '15 at 23:17
  • I do the same after lunch. – percusse Jun 07 '15 at 23:22
  • First of all, try to run the .exe file through cmd console rather than double-clicking it. That way the cmd window wont go away and you will be able to see what error it throws, and then post that. We would be able to help you better then. – Vikas Ojha Jun 08 '15 at 06:21

2 Answers2

0

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

Alex Ivanov
  • 695
  • 4
  • 6
  • I downloaded and installed that version of vcredist_x86.exe, and py2exe tutorial tells me to put some options so that py2exe can distribute those dlls. The data file option it tells me to add looks like data_files = [("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*'))], and I don't have such directory under Program Files. I have Visual Studio 8 directory, but not 9.0. I'm completely stuck. Thank you for your answer and I'd appreciate any further help here. – Deniz Jun 08 '15 at 08:55
  • sorry for the double post but py2exe says I should have a copy of those dlls in my visual studio folders if I have the rights to redistribute them. I have a VC folder in program files(x86) under microsoft visual studio 8, but it does not have copies of those dlls even though I have installed vcredist_x86 – Deniz Jun 08 '15 at 09:10
0

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.

zinon
  • 4,427
  • 14
  • 70
  • 112