views:

9220

answers:

9

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\build\bdist.win32\winexe
creating C:\DevSource\Scripts\ServerManager\build\bdist.win32\winexe\collect-2.6
creating C:\DevSource\Scripts\ServerManager\build\bdist.win32\winexe\bundle-2.6
creating C:\DevSource\Scripts\ServerManager\build\bdist.win32\winexe\temp
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 'win32pipe' (C:\Python26\lib\site-packages\win32\win32pipe.pyd -> win32pipe.pyd)
creating python loader for extension 'win32api' (C:\Python26\lib\site-packages\win32\win32api.pyd -> win32api.pyd)
creating python loader for extension 'select' (C:\Python26\DLLs\select.pyd -> select.pyd)
creating python loader for extension '_socket' (C:\Python26\DLLs\_socket.pyd -> _socket.pyd)
creating python loader for extension 'unicodedata' (C:\Python26\DLLs\unicodedata.pyd -> unicodedata.pyd)
creating python loader for extension 'wx._windows_' (C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows_.pyd -> wx._windows_.pyd)
creating python loader for extension 'wx._core_' (C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core_.pyd -> wx._core_.pyd)
creating python loader for extension 'wx._gdi_' (C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi_.pyd -> wx._gdi_.pyd)
creating python loader for extension 'wx._controls_' (C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_controls_.pyd -> wx._controls_.pyd)
creating python loader for extension '_ssl' (C:\Python26\DLLs\_ssl.pyd -> _ssl.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.

A: 

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.

sli
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.
Charles Anderson
Downloading MSVCR90.DLL adn copying it to Python26/DLLs worked for me!
Alex
+12  A: 

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.

Charles Anderson
I had same problem and applied your solution and it worked perfectly. Thanks for sharing!
I had same problem with PyQt4 app. Downloading the DLL helped, thanks!
kender
Link to msvcp90.dll - http://www.dll-files.com/dllindex/dll-files.shtml?msvcp90
Sridhar Ratnakumar
Great, but what is causing this dependancy?
phkahler
A: 

我英文不太好。。。不好意思 我也遇到这个问题了。。。google和live search得到的都是英文的 没办法 我只有看看了。。。 但是我还是看不懂 能用简洁的语言写出来吗???

Charles Anderson
Before you think of marking this response down, try translating it. You'll find that the author apologises for their poor English, and is just trying to get an answer like the rest of us.
Charles Anderson
+2  A: 

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.

+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.
Peter Hansen
A: 

我的wxpython app也遇到了這樣的問題,采用Bill的方式解決了該問題。thanks bill

setup.py文件內容如下:

coding=utf-8

from distutils.core import setup import py2exe

setup(windows=['main.py'], options = { "py2exe":{"dll_excludes":["MSVCP90.dll"]}})

A: 

Works like a charm. Thank you.

Please, keep the noise down. Comments go as comments, not as answers. If you don't have enough reputation to comment, and the comment is **not** essential, please restrain from posting to keep the noise down for people just looking for an answer.
voyager
A: 

import sys

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

+4  A: 

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.

resplin
As documented in this thread: http://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
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:http://sourceforge.net/mailarchive/message.php?msg_name=hlav67%24627%241%40ger.gmane.org
William Knight
+1  A: 

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!

george