簡體   English   中英

嘗試在Visual Studio 2013-15中從C ++執行python腳本時導入錯誤

[英]Import error when trying to execute a python script from C++ in Visual Studio 2013-15

我目前正在與Keras合作進行手勢識別項目。 所以我安裝了Anaconda和Python 2.7,我制作了一些與Spyder配合得很好的腳本。

在此之后,我想從我的主要軟件即Visual Studio 2015 C ++項目中使用它們。 所以我使用“python.h”,但我有導入問題

例如,如果我嘗試執行此代碼:

PyObject *pName, *pModule, *pDict, *pFunc, *pValue;         // Initialize the Python Interpreter

Py_Initialize(); 

FILE *fd =  fopen("test.py","r");

PyFile_FromString("test.py", "r");

PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject),"test.py", 1);   //file before returning.    

Py_Finalize();

cout << "Press any key to exit" << endl;    
_getch();

這是我將作為輸出得到的:

Traceback (most recent call last):  
File "test.py", line 4, in <module>  
from numpy import numpy 

ImportError: cannot import name numpy 

Press any key to exit

這是“test.py”:

from time import time,ctime 

from numpy import np 

np.random.seed(1337) 

//No need to add more code for this example 

print ('Today is',ctime(time()))

我仍然是Python的初學者,所以我看到有一些lib缺失,但我不明白為什么它在Spyder中工作但不在這里。

感謝您的關注 !

好的,我修好了。 事實上,我的計算機上有兩個pythons版本,而Visual Studio則使用了錯誤的版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM