python3.x - c++调用python3
问题描述
环境:win10 + vs2015( Debug 32位) + anaconda3(32位)
首先需要配置环境,创建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
运行崩溃:
求助如何解决。
------------------------------补充下---------------------
我的机器装了anaconda2和anaconda3,都是32位的,目前只用python3的,安装目录分别为:E:SoftwaresAnaconda3E:SoftwaresAnaconda2
问题解答
回答1:还是用py2吧,py2可以用,py3的上述问问题我还是没有解决
回答2:这个报错写得还算比较清楚的,加载 encodings 模块失败,这个要看是在什么地方 import 的。 然后检查
是否有这个模块
如果有这个模块,这个模块的地址是否在环境变量里面
相关文章:
1. javascript - iscroll5 的使用2. angular.js - 用angular2-cli打包项目之后,跳转路由刷新会报404的错误3. angular.js - 请教angularjs里html和js通信的问题4. angular.js - angular-ueditor使用中,插入图片,加载完成后不更新angularmodel的问题;5. angular.js - angular2动态显示隐藏组件问题6. angular.js - 我想实现打印angular $scope数据,代码如何实现呢?求教(如下图)7. angular.js - 在用会话存储传递参数时,使用angularjs冲突8. node.js - 怎么在初始化的时候使得一个子组件不加载?9. 老师,按tab键不起作用怎么回事10. 新人做网站求帮助