Python可执行文件中的dll加载错误(使用pywin32制作)

2 投票
2 回答
3272 浏览
提问于 2025-04-16 19:44

我用py2exe创建了Python可执行文件,分别使用了64位和32位的Python解释器。

在我的程序中,我使用了pywin32 com这个模块,所以在创建可执行文件之前,我下载并安装了64位和32位版本的程序。

64位的可执行文件运行得很好,但32位的有以下问题:

Traceback (most recent call last):
  File "program.py", line 11, in <module>
  File "win32com\__init__.pyc", line 5, in <module>
  File "win32api.pyc", line 12, in <module>
  File "win32api.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.

我直接运行了源代码,分别用python program.pyC:\python_32\python.exe program.py,这两个都能正常工作。

需要注意的是,我在一台64位的Windows 7电脑上测试了64位的可执行文件,而在一台32位的Windows XP电脑上测试了32位的可执行文件。

2 个回答

1

我在安装ArcGIS后,遇到了python27和pywin32的错误,这个是在我的windows2008 R2服务器上发生的(我想把我们的脚本集中管理)。

我发现我需要以管理员身份打开命令行窗口(在Windows中右键点击就可以找到这个选项),然后在c:\arcpy27\arcgis10.1>python c:/arcpy27/arcgis10.1/scripts/pywin32_postinstall.py -install这个路径下运行以下命令。

我看到很多人也遇到了这个问题,我尝试了很多方法,但最终这个方法成功安装了pywin32。

非常感谢你的解决方案。在我尝试了几次安装和卸载后,终于找到了你的方法,并根据我的版本进行了调整。

3

虽然这个问题已经存在很久了,但我今天遇到了这个问题。如果其他人也遇到的话,我用的是:

python /c/Python26/Scripts/pywin32_postinstall.py -install 这个命令(根据自己的情况修改路径)。这样做成功了:

$ python /c/Python26/Scripts/pywin32_postinstall.py -install
Copied pythoncom26.dll to C:\WINDOWS\system32\pythoncom26.dll
Copied pythoncomloader26.dll to C:\WINDOWS\system32\pythoncomloader26.dll
Copied pywintypes26.dll to C:\WINDOWS\system32\pywintypes26.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore\2.6\Help[None]=None
-> Software\Python\PythonCore\2.6\Help\PythonwinReference[None]='c:\\Python26\\Lib\\site-packages\\PyWin32.chm'
Pythonwin has been registered in context menu
Creating directory c:\Python26\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.`

(在WinXP SP3系统上)

撰写回答