我有PythonCode.py:
import os, ctypes
print "ctypes are imported"
和CCode.c:
...
PySys_SetPath(path_to_PythonCode);
PyObject *pModule = PyImport_ImportModule("PythonCode");
if (!pModule) {
PyErr_Print();
return;
}
...
PyErr_Print()
印刷:
Traceback (most recent call last): File ".../PythonCode.py", line 1,
in <module> import os, ctypes
ImportError: No module named ctypes
在终端中执行 Python 代码显示 ctypes 确实存在:
$ python --version
Python 2.7.1
$ python PythonCode.py
ctypes are imported
为什么 Python/C API 不能导入 ctypes?