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
高洛峰2017-05-16 13:29:09
Let’s use py2, py2 can be used, but I still haven’t solved the above problems with py3
怪我咯2017-05-16 13:29:09
This error report is quite clearly written. Loading the encodings
module failed. This depends on where it is imported.
Then check
Does this module exist
If there is this module, is the address of this module in the environment variable