Python 和 Py2Exe:“%1 不是有效的 Win32 应用程序”
我正在尝试将 python 项目编译为可执行文件。为了测试这一点,我安装了 Py2Exe,并尝试进行 Hello.py 测试。这是 hello.py:
print "Hello World!"
这是我的 setup.py:
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
我在命令行上执行以下操作:
python setup.py py2exe
我让它大部分工作,直到它开始“查找所需的 dll”,此时我们得到:
Traceback:
<some trace>
ImportError: DLL load failed: %1 is not a valid Win32 application.
Python 版本是 2.6.6,我在一台运行 Windows 7 的 32 位机器上。任何想法或帮助都非常感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据我的经验,
py2exe
使用起来相当困难,在它是否有效方面有点碰运气,并且与任何matplotlib< 一起工作绝对是一场噩梦/代码> 导入。
我意识到这个问题现在已经很老了,但我不确定为什么人们在有更流畅的功能替代方案的情况下继续使用 py2exe 。我使用 pyinstaller 得到了很好的结果(在我在这里问了一个问题后向我推荐了它,我也在与 py2exe 作斗争)。现在,每次我尝试它时,它都“正常工作”,所以如果您仍然有兴趣将 python 代码打包成可执行文件,那么尝试一下这个应用程序。
http://www.pyinstaller.org/
注意:
py2exe
已经好几年没有更新了,而 python 和第 3 方模块却更新了,这一定是它现在经常不能很好地工作的部分原因。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 anymatplotlib
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 withpyinstaller
(which was recommended to me after asking a question here on SO where I was also battling withpy2exe
). 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.听起来本教程中的步骤 5 描述了您所遇到的情况:
http://www.py2exe。 org/index.cgi/Tutorial#Step5
Sounds like step 5 in this tutorial describes what you are experiencing:
http://www.py2exe.org/index.cgi/Tutorial#Step5
我遇到了同样的问题,这就是我能够做的质量检查。基本上,我从 sqlite.org 下载了更新的 sqlite dll 文件。我用这个新文件替换了 py2exe 生成的 DLL 文件。之后该程序就起作用了。不过,请务必下载 32 位 DLL。
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.