python3.x - c++ calling python3
天蓬老师
天蓬老师 2017-05-16 13:27:09
0
2
918

Environment: win10 + vs2015 (Debug 32-bit) + anaconda3 (32-bit)

First you need to configure the environment, create a win32 console program, and then configure the project.
Project–>Properties–>vc++ directory–>Include directory Add the include directory in the python installation directory
Project–>Properties–>vc++ directory–>Library directory Add the libs directory in the python installation directory
Linker–>Input–>Additional Dependencies Add python36.lib

Go to this step to run the program:

#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;
}

The error is that python36_d.lib cannot be found.

Baidu solution: If the C++ project uses the debug version, you need to copy the python36.lib file under the libs folder in the python installation directory and change the name to python36_d.lib

Running crash:

Help how to solve it.

------------------------------Additional addition-------------- ------

My machine has anaconda2 and anaconda3 installed, both are 32-bit. Currently, I only use python3. The installation directories are:
E:\Softwares\Anaconda3
E:\Softwares\Anaconda2

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
小葫芦

Let’s use py2, py2 can be used, but I still haven’t solved the above problems with py3

刘奇

This error report is quite clearly written. Loading the encodings module failed. This depends on where it is imported.
Then check

  1. Does this module exist

  2. If there is this module, is the address of this module in the environment variable

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!