在C/C++中嵌入python, 用PyImport_ImportModule返回值总是为0的解决方法
2017-01-26 21:21
267 查看
import某块返回值为0的是因为:VC工程的当前工作目录和.py文件所在目录不一致导致的。
当.py文件和工程不在统一目录时,若要import .py文件,只需要在import之前增加python的搜索目录就可以了:
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('py所在目录')");
当.py文件和工程不在统一目录时,若要import .py文件,只需要在import之前增加python的搜索目录就可以了:
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('py所在目录')");
相关文章推荐
- C嵌入PyThon遇到问题解决方法
- 解决方案:c调用python,PyImport_Import或者PyImport_ImportModule总是返回为空
- c++加载python模块,但是PyImport_ImportModule老返回NULL
- c++中调用python脚本提示 error LNK2001: 无法解析的外部符号 __imp_Py_Initialize等错误的解决方法
- c++中调用python脚本提示 error LNK2001: 无法解析的外部符号 __imp_Py_Initialize等错误的解决方法
- python3.6安装Scrapy 提示 error: Microsoft Visual C++ 14.0 is required.的解决方法
- python pip install 总是出错的解决方法
- VS2010下,C++调用python的Runtime error R6034解决方法
- python 嵌入 C/C++方法
- C++调用Python脚本碰到的问题及解决方法【更新中】
- python 执行shell命令无法获取返回值的解决方法
- 嵌入python的c++程序发布(一)最简单的方法
- linux Eclipse上c++调用使用了tensorflow库的python程序遇到的问题及解决方法
- c++加载python模块,但是PyImport_ImportModule老返回NULL
- 【原】Python/C API使用方法简介 (在C/C++中嵌入Python)
- C++ 调用Python3 脚本中无法引入内建模块的问题 解决方法
- c++调用python链接的问题及解决方法
- c++中调用python脚本提示 error LNK2001: 无法解析的外部符号 __imp_Py_Initialize等错误的解决方法
- Flask+Bootstrap Web开发中Python代码嵌入html 时中文显示失败的解决方法
- Python/C API使用方法简介 (在C/C++中嵌入Python)