【发布时间】:2010-10-20 08:45:51
【问题描述】:
我正在尝试将 python 嵌入到 c 中以使用它进行配置:
如果我这样做:
/******************************************************************************
*
* Embeding Python Example
*
* To run:
* gcc -c test.c -o test.o -I"C:/Python25/include"
* gcc -o test.exe test.o -L"C:/Python25/libs" -lpython25
* test.exe
*
******************************************************************************/
#include <Python.h>
int main(int argc, char *argv[])
{
PyObject *run;
PyObject *globals = PyDict_New();
PyObject *locals = PyDict_New();
Py_Initialize();
run = PyRun_String("from time import time,ctime\n"
"print 'Today is',ctime(time())\n"
"test = 5\n"
"print test\n", Py_file_input, globals, locals);
Py_Finalize();
return 0;
}
我从 Microsoft VIsual C++ 运行时收到运行时错误,并显示以下消息:
Exception exceptions.ImportError: '__import__ not found' in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
我做错了什么?
【问题讨论】:
-
仅供参考,Lua 比 Python 更适合轻量级嵌入和配置文件。
标签: python c configuration embedding