VS2010에서 32 비트 프로젝트 용 Python C-Api를 사용하려고합니다.Python C-Api 32 비트 PyDict_Check Access Violation, Win7, Python 2.66
64 비트 및 32 비트 Python을 설치했습니다. 두 개의 버전을 구분하기 위해 32 비트 DLL의 이름을 'python26_32.dll'로 변경했습니다. VS dumpbin 및 lib 도구 (. https://adrianhenke.wordpress.com/2008/12/05/create-lib-file-from-dll/ 참조)를 사용하여 가져 오기 .lib 파일 'python26_32.lib'를 작성했습니다.
'pyconfig.h'를 조정하고 #pragma comment(lib...)
명세서의 주석 처리를 제거했습니다.
프로젝트가 32 비트에서 제대로 컴파일됩니다. exe를 실행하면 PyDict_Check
에 전화 할 때 액세스 위반이 발생합니다. 다른 방법은 전에 잘 (예를 들어 Py_Initialize
, PyRun_SimpleString
, PyDict_New
...) 일을 호출
여기 내 작은 예입니다
#include "stdafx.h"
#include "python.h" //include in stdafx.h has the same result
#include <iostream>
using std::cout; using std::endl;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Tryin to initialize Python." << endl;
Py_SetPythonHome("D:\\Python26_32");
Py_Initialize();
char *codeString =
"import platform\n"
"import sys\n"
"print platform.architecture()[0]\n"
"print sys.path\n"
"sys.path.insert(0,'D:\\Python26_32')\n"
"print sys.path\n";
PyRun_SimpleString(codeString);
PyObject *pDict;
pDict = PyDict_New();
PyDict_SetItemString(pDict, "Key1", PyString_FromString("Value1"));
int i = PyDict_Check(pDict);
cout << "working" << endl;
return 0;
}
내가 발견 한이 'PyDict_Check'는 DLL의 수출 아니라고. 이것은 파이썬 헤더 파일에 정의되어 있습니다.
'경로'(Windows 및 api (예 참조))를 조정하려고했으나 도움이되지 않았습니다.
64 비트 버전은 relvant VC++ 디렉토리와 Py_SetPythonHome
정책을 변경 한 후 (잘 작동합니다.
그냥 PyDict_CheckExact
을 시도하는 것이, 나를 가장 혼란
이 작동합니다.
많은 감사를 도와.