C++调用python出错,高人帮忙,没分了,555,该如何处理
C++调用python出错,高人帮忙,没分了,555
C++调用python,PyImport_ImportModule|PyObject_GetAttrString出错,高人帮忙,没分了,555
#Filename test.py
you = "world!"
print "aaaaaaaa"
def Hello():
print "Hello, world!"
Hello()
#include "stdafx.h"
//#include <python.h>
int main()
{
Py_Initialize();
PyObject * pModule = NULL;
PyObject * pFunc = NULL;
pModule = PyImport_ImportModule("test");
//pModule = PyImport_ImportModule("test.py");
pFunc = PyObject_GetAttrString(pModule, "Hello");
//pFunc = PyObject_GetAttrString(pModule, "you");
PyEval_CallObject(pFunc, NULL);
Py_Finalize();
return 0;
}
test.py应该放在哪呢?
我把py文件在python25/lib, projectdir/debug和projectdir下各放一份,
调试看到,pModule 不为0了,pFunc 还是0。
为了解决没有python25_d.lib的问题,我在stdafx.h里有如下设定
stdafx.h:
#pragma once
#include <afx.h>
#include <afxcmn.h>
#ifdef _DEBUG
#undef _DEBUG
#include "E:\software\Python25\include\Python.h"
#define _DEBUG
#else
#include "E:\software\Python25\include\Python.h"
#endif
------解决方案--------------------
咋老有人犯这个问题呢?
就不能把test.py换个别的模块名试试?
test是系统模块
NAME
test - # Dummy file to make this directory a package.
FILE
/opt/Python-2.5.2/lib/python2.5/test/__init__.py
C++调用python,PyImport_ImportModule|PyObject_GetAttrString出错,高人帮忙,没分了,555
#Filename test.py
you = "world!"
print "aaaaaaaa"
def Hello():
print "Hello, world!"
Hello()
#include "stdafx.h"
//#include <python.h>
int main()
{
Py_Initialize();
PyObject * pModule = NULL;
PyObject * pFunc = NULL;
pModule = PyImport_ImportModule("test");
//pModule = PyImport_ImportModule("test.py");
pFunc = PyObject_GetAttrString(pModule, "Hello");
//pFunc = PyObject_GetAttrString(pModule, "you");
PyEval_CallObject(pFunc, NULL);
Py_Finalize();
return 0;
}
test.py应该放在哪呢?
我把py文件在python25/lib, projectdir/debug和projectdir下各放一份,
调试看到,pModule 不为0了,pFunc 还是0。
为了解决没有python25_d.lib的问题,我在stdafx.h里有如下设定
stdafx.h:
#pragma once
#include <afx.h>
#include <afxcmn.h>
#ifdef _DEBUG
#undef _DEBUG
#include "E:\software\Python25\include\Python.h"
#define _DEBUG
#else
#include "E:\software\Python25\include\Python.h"
#endif
------解决方案--------------------
咋老有人犯这个问题呢?
就不能把test.py换个别的模块名试试?
test是系统模块
NAME
test - # Dummy file to make this directory a package.
FILE
/opt/Python-2.5.2/lib/python2.5/test/__init__.py