我在python源文件中写了一个测试函数,想在c++中调用,但是在调用的过程中遇到了一个问题:只要我导入了lxml模块,PyImport_ImportModule函数失败返回NULL,去掉lxml相关就可以正常调用返回。
python代码如下
Test.py
import os
import sys
import requests
from lxml import html #只要加这个就错误,换成import lxml也一样
def foo():
host = "http://www.baidu.com"
s = requests.session()
res = s.get(host)
return res
c++代码如下
Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')");
PyObject* pModule = PyImport_ImportModule("Test");
if (pModule == NULL || PyErr_Occurred())
{
PyErr_Print();
}
PyObject* pDict = PyModule_GetDict(pModule);
PyObject *pFunHi = PyDict_GetItemString(pDict, "foo");
PyObject *ret = PyObject_CallFunction(pFunHi,NULL);
Py_DECREF(pFunHi);
Py_Finalize();
错误消息:
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\test\Test\Debug\Test.py", line 4, in <module>
from lxml import html
File "E:\python27\lib\site-packages\lxml\html\__init__.py", line 54, in <module>
from .. import etree
ImportError: DLL load failed: Unable to find the specified module。
请问怎么正确用lxml模块?
라이브러리 때문이니 다른 라이브러리를 다운받으세요