py2exe fails to generate an executable

Question:

I am using python 2.6 on XP. I have just installed py2exe, and I can successfully create a simple hello.exe from a hello.py. However, when I try using py2exe on my real program, py2exe produces a few information messages but fails to generate anything in the dist folder.

My setup.py looks like this:

from distutils.core import setup
import py2exe

setup(console=['ServerManager.py'])

and the py2exe output looks like this:

python setup.py py2exe
running py2exe
creating C:DevSourceScriptsServerManagerbuild
creating C:DevSourceScriptsServerManagerbuildbdist.win32
   ...
   ...
creating C:DevSourceScriptsServerManagerdist
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'wx._misc_' (C:Python26libsite-packageswx-2.8-msw-unicodewx_misc_.pyd -> wx._misc_.pyd)
creating python loader for extension 'lxml.etree' (C:Python26libsite-packageslxmletree.pyd -> lxml.etree.pyd)
   ...
   ...
creating python loader for extension 'bz2' (C:Python26DLLsbz2.pyd -> bz2.pyd)
*** finding dlls needed ***

py2exe seems to have found all my imports (though I was a bit surprised to see win32 mentioned, as I am not explicitly importing it). Also, my program starts up quite happily with this command:

python ServerManager.py

Clearly I am doing something fundamentally wrong, but in the absence of any error messages from py2exe I have no idea what.

Asked By: Charles Anderson

||

Answers:

The output says you’re using WX. Try running py2exe with your script specified as a GUI app instead of console. If I’m not mistaken, that tends to cause problems with py2exe.

Answered By: user13876

I’ve discovered that py2exe works just fine if I comment out the part of my program that uses wxPython. Also, when I use py2exe on the ‘simple’ sample that comes with its download (i.e. in Python26Libsite-packagespy2exesamplessimple), I get this error message:

*** finding dlls needed ***
error: MSVCP90.dll: No such file or directory

So something about wxPython makes py2exe think I need a Visual Studio 2008 DLL. I don’t have VS2008, and yet my program works perfectly well as a directory of Python modules. I found a copy of MSVCP90.DLL on the web, installed it in Python26/DLLs, and py2exe now works fine.

I still don’t understand where this dependency has come from, since I can run my code perfectly okay without py2exe. It’s also annoying that py2exe didn’t give me an error message like it did with the test_wx.py sample.

Further update: When I tried to run the output from py2exe on another PC, I discovered that it needed to have MSVCR90.DLL installed; so if your target PC hasn’t got Visual C++ 2008 already installed, I recommend you download and install the Microsoft Visual C++ 2008 Redistributable Package.

Answered By: Charles Anderson

I put this in all my setup.py scripts:

distutils.core.setup(
    options = {
        "py2exe": {
            "dll_excludes": ["MSVCP90.dll"]
        }
    },
    ...
)

This keeps py2exe quiet, but you still need to make sure that dll is on the user’s machine.

Answered By: Bill
import sys

sys.path.append('c:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT')
Answered By: T. PH.

It looks like this is only a dependency for Python 2.6. I wasn’t getting this error under 2.5, but after the upgrade I am.

This email thread has some background for why the problem exists and how to fix it:
http://www.nabble.com/py2exe,-Py26,-wxPython-and-dll-td20556399.html

I didn’t want to have to install the vcredist. My application currently requires no installation and can be run by non-administrators, which is behavior I don’t want to lose. So I followed the suggestions in the links and got the necessary Microsoft.VC90.CRT.manifest and msvcr90.dll by installing Python “for this user only”. I also needed msvcp90.dll that I found in the WinSxS folder of an “all users” Python 2.6 install. Since I already had two of the three, I included msvcm90.dll to prevent future errors though I didn’t get any immediate errors when I left it out. I put the manifest and the three DLLs in the libs folder used by my frozen application.

The trick I had to perform was including an additional copy of the manifest and msvcr90.dll in the root of my application folder next to by py2exe generated executable. This copy of the DLL is used to bootstrap the application, but then it appears to only look in the libs folder.

Hopefully that discovery helps someone else out.

Also, I had the same problem with having py2exe log a real error message. Then I realized that stderr wasn’t getting redirected into my log file. Add “> build.log 2>&1” on the command line where you invoke py2exe.

Answered By: resplin

Just for your info, for me it worked to copy the files

Microsoft.VC90.CRT.manifest
msvcr90.dll

into the directory with the .exe on the user’s machine (who has no python or VC redistributable installed).

Thanks for all the hints here!

Answered By: george

wxPython has nothing to do with it. Before Python 2.6, Python used Visual Studio 2003 as their Windows compiler. Beginning with 2.6, they switched to Visual Studio 2008, which requires a manifest file in some situations. This has been well documented. See the following links:

http://wiki.wxpython.org/py2exe

http://py2exe.org/index.cgi/Tutorial#Step52

Also, if you’re creating a wxPython application with py2exe, then you want to set the windows parameter, NOT the console one. Maybe my tutorial will help you:

http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/

Answered By: Mike Driscoll
Answered By: bazzinga
import sys

sys.path.append('C:\WINDOWS\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2')

On each Windows, you can find the file MSVCP90.dll in some subdirectory in C:\WINDOWS\WinSxS\

In my case, the directory was: x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2.

Go to C:\WINDOWS\WinSxS\ and use windows file search to find MSVCP90.dll.

Answered By: Egor

There is some info on the wxPython wiki.

Deploy a Python app

py2exe with wxPython and Python 2.6

Answered By: Werner

On my win8.1, I do not find the path

c:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT

On the contrary , the dll is found in

C:/WINDOWS/WinSxS/x86_Microsoft.VC90.CRT_XXXXXXX

The XXX may vary according to your PC

You may search in the path , then add the path in you setup.py

import sys
sys.path.append('C:/WINDOWS/WinSxS/x86_Microsoft.VC90.CRT_XXXXXXX')
Answered By: petitchamp
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.