开发者

Python And Py2Exe: "%1 Is Not A Valid Win32 Application"

开发者 https://www.devze.com 2023-01-24 07:44 出处:网络
I\'m trying to compile a python project into an executable. To test this, I\'ve got Py2Exe installed, and am trying to do their Hello.py test. Here is hello.py:

I'm trying to compile a python project into an executable. To test this, I've got Py2Exe installed, and am trying to do their Hello.py test. Here is hello.py:

print "Hello World!"

Here is my setup.py:

from distutils.core import setup
import py2exe

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

I do the following on the command line:

开发者_运维技巧
python setup.py py2exe

And I get it mostly working until it start 'finding dlls needed', at which point we get:

Traceback:
<some trace>
ImportError: DLL load failed: %1 is not a valid Win32 application.

Python version is 2.6.6, and I'm on a 32-bit machine running Windows 7. Any ideas or help most appreciated.


In my experience py2exe is rather difficult to use, a bit hit-and-miss in terms of whether it will work or not, and an absolute nightmare to get working at all with any matplotlib import.

I realise this question is quite old now, but I am not sure why people continue to use py2exe when there are much smoother functioning alternatives available. I have have good results with pyinstaller (which was recommended to me after asking a question here on SO where I was also battling with py2exe). Now every time I have tried it it "just worked", so if you're still interested in packing up python code into executables then try give this app a shot instead.

http://www.pyinstaller.org/

Note: py2exe hasn't been updated for some years, while python and 3rd party modules have, which must be partly why it often doesn't work particularly well these days.


Sounds like step 5 in this tutorial describes what you are experiencing:

http://www.py2exe.org/index.cgi/Tutorial#Step5


I had this same problem, this is what I was able to do Q-A. Basically, I downloaded the updated sqlite dll file from sqlite.org. I replaced the py2exe generated DLL file with this new file. The program worked after that. Do make sure you download the 32-bit DLL, however.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号