2017-04-26 56 views
0

设置:win10 + vs2015(调试32位)+ anaconda3(32位)C++使用python3,运行错误

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

当它运行时,程序崩溃。

Crash image

+0

这与此有关吗? http://stackoverflow.com/questions/38132755/importerror-no-module-named-encodings此外,请检查此线程:https://bugs.python.org/issue27054 – AndyG

+0

确保环境变量设置正确,特别是'PYTHONHOME'。 – zmo

回答

0

根据this Python thread你需要安装Python 3.x作为管理员。在安装右键>以管理员身份运行

此外,请安装后,你的环境变量,以确保PYTHONPATHPYTHONHOME已设置为在您安装的模块都可以找到的位置。

+0

pythonhome和pythonpath都可以。无论如何,3Q我再次失败。我使用python2,我只是做到了。 – LaoJiu