2012-06-26 22 views
0

當我試圖把Python WX用C這樣的:在VisualStudio的2005 C/C++中嵌入wxPython的失敗

#include "stdafx.h" 
#ifdef _DEBUG 
    #undef _DEBUG 
    #include <Python.h> 
    #define _DEBUG 
#else 
    #include <Python.h> 
#endif 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    PyObject* pyModule; 
    Py_Initialize(); 
    //_pyModule = PyImport_ImportModule("__main__"); 
    //_pyModule = PyImport_ImportModule("csi"); 
    pyModule = PyImport_ImportModule("wx"); 
    if(!pyModule) 
    PyErr_Print(); 
    return 0; 
} 

失敗:

->Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\wx-2.8-msw-ansi\wx\__init__.py", line 45, in <module> 
    from wx._core import * 
    File "C:\Python27\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line 4, in <module> 
    import _core_ 
    ImportError: DLL load failed: The specified module could not be found. 

可以用MSVC * 90個問題。 dll文件?

我使用VS2005,Python 2.7版,wxPython的2.8.12.1(ANSI)爲Python 2.7

此外MS VC++ 2008/2010可再分發的安裝位置。

感謝您的幫助。

+0

爲什麼要那樣做?你可以使用wxWidgets,因爲它實際上是C++。 –

回答

3

最後我找到了解決辦法:

這是一個清單問題。由於Microsof DLL地獄......

這有助於:

//_core_.pyd ImportError 
// _core_.pyd is in fact a dll. it can be renamed. 
// The problem is that _core_.pyd depends on some Microsoft.VC90.CRT libraries 
//this dependency must be added to make it work 
#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' language='*'\"") 
+0

這真的起作用,我使用了一個擴展的python模塊,當我在Windows上啓動python解釋器並導入該模塊時,沒有錯誤。但是當我在一個使用boost python的項目中使用這個模塊時,'boost :: python :: import'(它使用'PyImport_ImportModule')將始終引發導入錯誤。 – wynemo