python加载dll出错_在python可执行DLL加载错误从pywin32制成

本文解决了一个使用py2exe将包含pywin32 com模块的Python程序打包成32位可执行文件时遇到的问题。在尝试运行32位可执行文件时出现了DLL加载失败的错误。通过重新安装pywin32并手动复制必要的DLL文件到系统目录中成功解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I created python executables with py2exe with both 64bit python interpreter and 32 bit python interpreter.

In my program, I use the module pywin32 com, and so I dl'ed and installed both the 64bit and 32bit versions of the program prior to creating the executable.

The 64bit exe works fine, but the 32 bit one has the following problem:

Traceback (most recent call last):

File "program.py", line 11, in

File "win32com\__init__.pyc", line 5, in

File "win32api.pyc", line 12, in

File "win32api.pyc", line 10, in __load

ImportError: DLL load failed: The specified procedure could not be found.

I tried both versions by running the source directly, ie python program.py and C:\python_32\python.exe program.py and both work fine.

Note I tested the 64bit exe on a 64bit windows 7 computer and the 32bit exe on a 32bit windows XP computer.

解决方案

Older than everything ever, but I stumbled on this problem today, and if anyone else does, what I ran was:

python /c/Python26/Scripts/pywin32_postinstall.py -install from the commandline (change values to fit). That worked:

$ 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.`

(On WinXP SP3)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值