52

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:\DevSource\Scripts\ServerManager\build
creating C:\DevSource\Scripts\ServerManager\build\bdist.win32
   ...
   ...
creating C:\DevSource\Scripts\ServerManager\dist
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'wx._misc_' (C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_misc_.pyd -> wx._misc_.pyd)
creating python loader for extension 'lxml.etree' (C:\Python26\lib\site-packages\lxml\etree.pyd -> lxml.etree.pyd)
   ...
   ...
creating python loader for extension 'bz2' (C:\Python26\DLLs\bz2.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.

2
  • If there really is no more output, from py2exe, this is a really odd one. Usually it will tell you why it fails. Best I can say is have you read through all these: py2exe.org/index.cgi/Py2exeAndwxPython
    – Ali Afshar
    Nov 27, 2008 at 11:11
  • Charles: Am checking this one regularly, am intrigued to the solution. If you figure it, please post back. Thanks.
    – Ali Afshar
    Nov 27, 2008 at 22:47

11 Answers 11

42

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.

2
  • 5
    +1: This answer is really the only correct one for the original question, which reported a problem during building with py2exe. It's quite true (as noted in Charles' own answer) that you still need the DLL to be on the target machine, but assuming you have dealt with that and you still get this error on the build machine (as I just did) Bill's answer above nicely shuts up py2exe and lets your build complete. Jun 28, 2010 at 14:46
  • This had been giving my problems for a while, just tried this fix and it worked 100%. Feb 2, 2011 at 4:38
41

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 Python26\Lib\site-packages\py2exe\samples\simple), 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.

7
  • 4
    I had same problem with PyQt4 app. Downloading the DLL helped, thanks!
    – kender
    Mar 29, 2009 at 5:30
  • 3
    Great, but what is causing this dependancy?
    – phkahler
    Feb 16, 2010 at 15:18
  • 2
    MSVCP90.dll can also be found in the official Microsoft package (x86). It may be necessary to deploy this package to all machines running this application as well!
    – exhuma
    Nov 3, 2010 at 8:26
  • 1
    @SridharRatnakumar: not only this is inadvisable to download random DLLs from this site but including it in your package probably violates the license. If you own Visual Studio, there is a redist.txt file that lists which file you may redistribute as part of your installation if you really need to do so. Otherwise, just use the only solid and approved method: bundle the vcredist_x86.exe with your installation. Bonus points if your installer is able to run it in the background. Yes, it makes your package bigger. But at least we STOP advising people to download DLLs like this.
    – user948581
    Apr 25, 2016 at 15:32
  • 1
    @CharlesAnderson: same remark, don't install (or worse, redistribute) a DLL you "found on the web". But at least you get it right with your last sentence.
    – user948581
    Apr 25, 2016 at 15:34
9

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/

6

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.

2
  • 1
    As documented in this thread: stackoverflow.com/questions/1570542 my solution wasn't as clever as I thought; it lead to other errors. I'm just going to have to install vcredist. Arg
    – resplin
    Oct 16, 2009 at 5:18
  • 2
    I say that you are still clever. Maybe it doesn't work with an app that uses SQLite, but I tried the trick of adding the 3 dlls and the manifest file to the runtime directory. This allowed my fairly simple Python26/py2exe app to run correctly without errors and without having to install vc_redist on the machine (Win2003 Server), which I couldn't do anyhow on a client's machine. Werner F. Bruhin has more details on this simple solution here: sourceforge.net/mailarchive/… Feb 24, 2010 at 22:43
6
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.

0
3

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!

1
  • 1
    I just wanted to say that Microsoft.VC90.CRT.manifest name is crucial. My manifest was named x86_Microsoft.VC90.CRT_1fc8b3b9..._9.0.21022.8_x-ww_d08.....manifest and it gave me some headache wondering why it wasn't working. Thanks! May 21, 2013 at 17:58
1

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.

2
  • Okay, my setup.py now looks like this: from distutils.core import setup import py2exe setup(windows = [{"script": 'ServerManager.py'}]) but that had no effect. However, I have managed to prove that wxPython is causing the problem. If I don't import wx, py2exe works perfectly. Nov 28, 2008 at 9:32
  • Downloading MSVCR90.DLL adn copying it to Python26/DLLs worked for me!
    – Alex
    Aug 12, 2009 at 15:15
1

Try this: http://www.py2exe.org/index.cgi/Tutorial#Step52

It worked for me

-1

There is some info on the wxPython wiki.

Deploy a Python app

py2exe with wxPython and Python 2.6

-1

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')
-2
import sys

sys.path.append('c:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT')
1
  • Could you explain to OP what this code does? (edit your post). Thanks
    – Paco
    Feb 10, 2015 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.