本文介绍了在初始化嵌入蟒蛇错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在工作C code IM调用Python函数,有错误就Py_Initialize()的错误是导入错误:没有模块命名的网站。香港专业教育学院试图把Py_SetProgramName(的argv [0]),但它不工作。 cmd中调用cInterfacePython Test.py乘3 2(EXE是cInterfacePython)

when im running C code to call python functions, there's error on Py_Initialize() The error is ImportError: No module named site. Ive tried to put Py_SetProgramName(argv[0]) but it doesnt work. The cmd call is cInterfacePython Test.py multiply 3 2 (exe is cInterfacePython)

推荐答案

我不得不渣土约一点与PATH环境-VAR以及PYTHONPATH使嵌入时的东西更好地工作。

I had to muck about a bit with the PATH env-var as well as PYTHONPATH to make things work better when embedding.

Py_SetProgramName并不重要,它主要是作为内部参考等...

Py_SetProgramName is not important, it's mostly for internal reference etc...

所以,我建议你找哪里Python是本地安装(这是可在Windows计算机上的注册表),并使用 SETENV 来PATH和PYTHONPATH设置为合适的东西。这将是PATH的python.exe目录(如上您的评论),以及设置PYTHONPATH到你从嵌入exe文件运行你自己的Python code和相关的库目录。

So, I suggest you find where python is installed locally (this is available in the registry on Windows machines) and use setenv to set PATH and PYTHONPATH to something appropriate. That would be the python.exe directory for PATH (as in your comment above), as well setting PYTHONPATH to the dir with your own python code and related libraries that you're running from the embedding exe.

然后运行Py_Initialize,看看是否正确的事情发生了。如果您需要修改PYTHONPATH初始化之后用PySys_SetPath()修改的sys.path。

Then run Py_Initialize and see if the right thing happens. If you need to modify PYTHONPATH afterward initialization, modify sys.path using PySys_SetPath().

这篇关于在初始化嵌入蟒蛇错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 16:28
查看更多