使用py2exe时遇到问题
我正在尝试制作一个exe文件。我使用的是Python 2.7,听说我安装了正确版本的py2exe。我写了一段简单的setup.py代码来创建exe文件。
但是,当我运行它时,出现了错误:
错误:MSVCP90.dll:没有这样的文件或目录
我尝试了两种方法来解决这个问题:
- 我安装了MSVCP90.dll文件,并把它放在Python 27的dll文件夹里,然后运行了setup。这成功创建了一个可执行文件。但是,当我尝试运行这个可执行文件时,它显示:
程序无法启动,因为计算机上缺少MSVCR90.dll。请尝试重新安装程序以解决此问题。
我下载了这个dll,并把它放在Python 27和exe文件夹里,想看看会发生什么,但都没有成功。
- 我在setup文件中排除了MSVCP90.dll文件。再次,这成功创建了一个可执行文件,但点击它时又遇到了同样的错误。
我已经多次重新安装Python和py2exe,但这并没有帮助。
有没有人有什么建议,能让我这个可执行文件正常工作?
1 个回答
0
正如你在评论中提到的,你正在使用wxpython。我之前也遇到过wxpython和py2exe的问题。我是通过给exe文件添加MSVCP90.dll的清单来解决的。你可以试着把这些代码加到setup.py里,看看能不能解决你的问题。
manifest = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="5.0.0.0"
processorArchitecture="x86"
name="%(prog)s"
type="win32"
/>
<description>%(prog)s</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false">
</requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.VC90.CRT"
version="9.0.21022.8"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b">
</assemblyIdentity>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>"""
...
windows = [{"script":"myscript.pyw",'other_resources': [(24,1,manifest)]}]