问题描述
我正在尝试访问位于64位处理器PC中的c:/ Program Files(x86)文件夹中的dll。
I am trying to access a dll located in the "c:/Program Files (x86)" folder in a 64-bits processor PC.
如果我使用os.path.exists来检查DLL是否存在,我收到一个确定的答案:
If I use os.path.exists to check if the dll exists, I receive an afirmative answer:
>>> print os.path.exists('c:/Program Files (x86)/Some Folder/SomeDll.dll')
True
但是当我尝试使用ctypes加载dll时,我收到以下错误:
But when I try to load the dll using ctypes, I get the following error:
>>> from ctypes import WinDLL
>>> some_dll = WinDLL('c:/Program Files (x86)/Some Folder/SomeDLL.dll')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python26\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
在32位PC中,dll位于在c:/ Program Files文件夹中,我可以打开它没有问题。我认为问题可能是文件夹名称中存在括号。由于返回的异常是WindowsError,它似乎是负责加载库的操作系统函数的缺陷。
In 32-bit PCs the dll is located in the "c:/Program Files" folder and I can open it without problems. I think that perhaps the problem is the presence of parenthesis in the folder name. As the returned exception was a WindowsError, it seems that it is a flaw in the operating system function responsible of loading libraries.
所以问题是:如何加载一个dll位于c:/ Program Files(x86)文件夹中?我不能将dll复制到另一个目的地,它必须位于原始路径...
So, the question is: how do I load a dll located in the "c:/Program Files (x86)" folder? I can't copy the dll to another destination, it must be located in the original path...
谢谢!
推荐答案
您是否尝试过C:/ Progra〜1 / SomeFolder / SomeDll?
Have you tried "C:/Progra~1/SomeFolder/SomeDll" ?
另一个建议:
os.chdir(r"C:\Program Files(x86)\SomeFolder")
the_dll = WinDLL("SomeDLL.dll")
这篇关于使用ctypes(python)加载带有括号的路径中的dll错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!