如何修复这个DLL加载的Python错误?

1 投票
1 回答
11683 浏览
提问于 2025-04-15 22:49

我在我的Python代码中使用了一个C++的动态链接库(dll)。

当我在自己的电脑上运行这个Python应用时,一切都很好,但当我把所有文件复制到另一台电脑上,就出现了这个问题:

Traceback (most recent call last):
 File "C:\users\Public\SoundLog\Code\Código Python\SoundLog\SoundLog.py", line 9, in <module>
   from Auxiliar import *
 File "C:\users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar\DataCollection.py", line 4, in <module>
   import SoundLogDLL
 File "C:\users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar\SoundLogDLL.py", line 4, in <module>
   dll = cdll.LoadLibrary(os.environ['PUBLIC'] + "\\SoundLog\\DLLs\\ForPython\\SoundLogC++WrapperDLL.dll")
 File "C:\Python26\lib\ctypes\__init__.py", line 431, in LoadLibrary
   return self._dlltype(name)
 File "C:\Python26\lib\ctypes\__init__.py", line 353, in __init__
   self._handle = _dlopen(self._name, mode)
WindowsError: [Error 14001] The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail

我该怎么解决这个问题,让我的Python应用在每台电脑上都能正常工作呢?

注意:我只需要它们在像我这样的Windows 7系统上运行。我还在另一台Windows 7电脑上测试过(都是32位的)。

1 个回答

3

你正在使用一个DLL文件,这个文件依赖于一个没有在目标电脑上安装的Microsoft Visual C++运行库。你有几个选择:

  • 可以在目标电脑上安装或复制Visual C++运行库。安装的方法是将合并模块添加到你的安装程序中(如果你有的话),或者运行redistributable安装程序(vcredist.exe)。关于各种方法的详细说明可以在这里找到,适用于VS2005(其他版本也类似)。

  • 如果你是自己制作的DLL,可以更改项目设置,将运行库静态链接到DLL中。想知道怎么做,可以查看这个回答

撰写回答