在 python 2.6 上加载 win32file.pyd 时出现问题
即使是使用 win32file 的简单脚本,我也无法使 py2exe 正确打包 我不断收到以下错误消息:
Traceback (most recent call last):
File "dependency_checker.py", line 1, in <module>
File "win32file.pyc", line 12, in <module>
File "win32file.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.
脚本如下所示:
import win32file
print "Hello world!"
这是 setup.py:
from distutils.core import setup
import py2exe
setup(console=['dependency_checker.py'])
您以前遇到过类似的问题吗?
版本:
Python 2.6.2、py2exe 0.6.9、pywin32-214、Windows 7 和 Windows XP Pro 作为目标计算机
更新:
- 我可以在创建它的 Windows 7 上运行捆绑程序,但我无法在XP机器上运行。
win32file.pyc 引发错误的部分如下所示:
<前><代码>>>> imp.load_dynamic('win32file', r'C:\test\setup-test\src\dist\win32file.pyd')
上面的行在我的开发盒(Windows 7)上运行正确,而在测试盒(Windows XP)上返回错误。
** 更新 2: **
当我使用 imp.load_dynamic 从 python 安装中加载 win32file 时,我可以重新加载 dist 文件夹的 win32file.pyd 而不会出现错误。
I can't make py2exe to pack correctly even a simple script that uses win32file
I'm constantly getting the following error message:
Traceback (most recent call last):
File "dependency_checker.py", line 1, in <module>
File "win32file.pyc", line 12, in <module>
File "win32file.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.
The script looks as follows:
import win32file
print "Hello world!"
And here is the setup.py:
from distutils.core import setup
import py2exe
setup(console=['dependency_checker.py'])
Have you had similar problem before?
Versions:
Python 2.6.2, py2exe 0.6.9, pywin32-214, Windows 7 and Windows XP Pro as target machine
UPDATE:
- I can run the bundled program on my windows 7 where it was created but I can't run it on the XP machine.
The part of win32file.pyc that throws the error looks as follows:
>>> imp.load_dynamic('win32file', r'C:\test\setup-test\src\dist\win32file.pyd')
The line above on my dev box (windows 7) runs correctly while on test box (windows XP) returns the error.
** UPDATE 2: **
When I use imp.load_dynamic to load win32file form python installation then I can reload the win32file.pyd for the dist folder without the error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决办法是删除被py2exe错误复制到dist目录的MSWSOCK.dll。
我使用 procmon 和 listdll 来检查导入成功时 win32file.pyd 加载的内容以及导入失败时加载的 dll。然后查看我检查过的 dll 列表是否正确加载。来自 dist 文件夹的 python dll 和来自 windows 文件夹的 windows dll。
这是运行良好的 setup.py
The soution was to remove MSWSOCK.dll that was copied to the dist directory by py2exe incorrectly.
I've used procmon and listdll to check what is loaded by win32file.pyd when import is successfull and what dll are loaded when import fails. Then having the list of dlls I've checked if they are loaded correctly ie. python dlls from dist folder and windows dlls from windows folder.
Here is the setup.py that works fine