2010-05-17 127 views
1

我在我的python代碼中使用了一個C++ dll。 當我在我的電腦上運行我的Python應用程序,它工作正常,但當我都複製到另一臺計算機出現這種情況:如何解決這個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上工作。而我在另一臺win7電腦上測試(都是32位)。

回答

3

您正在使用一個DLL,它依賴於未安裝在目標計算機上的Microsoft Visual C++運行庫。您有幾個選項:

  • 安裝或將Visual C++運行時庫複製到目標計算機。通過向安裝程序添加合併模塊(如果有的話)或運行可再發行組件安裝程序(vcredist.exe)來完成安裝。對於VS2005,各種方法記錄爲here(其他版本將類似)。

  • 如果您構建了DLL,則可以更改項目設置以靜態鏈接運行時庫。請參閱this answer以瞭解如何完成此操作。

+0

具體來說,ctypes庫。我不確定有多少Windows支持它。 – rossipedia 2010-05-17 21:13:52

+0

@Bryan:Windows支持ctypes庫就好了。這裏的錯誤不是由ctypes引起的,而是由使用ctypes加載的DLL造成的。 – interjay 2010-05-17 21:21:27

+0

我已經完成了安裝Visual C++運行時庫並將項目的執行從Debug更改爲Release ^^ – 2010-05-24 16:09:26