2017-04-26 55 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