您的位置:首页技术文章
文章详情页

python3.x - c++调用python3

【字号: 日期:2022-10-11 17:45:59浏览:46作者:猪猪

问题描述

环境:win10 + vs2015( Debug 32位) + anaconda3(32位)

python3.x - c++调用python3

首先需要配置环境,创建win32控制台程序,然后对工程进行配置。 项目–>属性–>vc++目录–>包含目录 添加python安装目录中include目录 项目–>属性–>vc++目录–>库目录 添加python安装目录中libs目录 链接器–>输入–>附加依赖项 添加python36.lib

到这步运行程序:

#include <iostream> #include <stdio.h>#include <stdlib.h>#include <Python.h>#include <string.h>using namespace std;int main(){ Py_Initialize(); PyRun_SimpleString('import pylab'); PyRun_SimpleString('pylab.plot(range(5))'); PyRun_SimpleString('pylab.show()'); Py_Exit(0); return 0;}

报错找不到 python36_d.lib。

百度解决方案:如果 C++ 工程采用debug版本,需要将 python 安装目录里 libs 文件夹下的 python36.lib 文件复制,并将名字改成 python36_d.lib

运行崩溃:

python3.x - c++调用python3

求助如何解决。

------------------------------补充下---------------------

我的机器装了anaconda2和anaconda3,都是32位的,目前只用python3的,安装目录分别为:E:SoftwaresAnaconda3E:SoftwaresAnaconda2

问题解答

回答1:

还是用py2吧,py2可以用,py3的上述问问题我还是没有解决

回答2:

这个报错写得还算比较清楚的,加载 encodings 模块失败,这个要看是在什么地方 import 的。 然后检查

是否有这个模块

如果有这个模块,这个模块的地址是否在环境变量里面

标签: Python 编程
相关文章: