自己使用的conda創建的python,安裝了Pytorch環境,在jupyter上可以正常使用,命令行也可以正常使用,但是用Pycharm創建新項目時,使用conda創建的Python環境,在正常的py文件中import時報錯,而且控制台也是import報錯。
因為在命令行中沒錯,在Pycharm中使用錯誤,則可能還是環境沒有配置好,它報錯是找不到模塊,即它的環境目錄沒有放入進去,解決方法如下
報錯形式:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.6 from "D:\APP\Anaconda\envs\torch\python.exe"
* The NumPy version is: "1.19.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: 找不到指定的模塊。
解決方法:
點擊Edit Configurations->Environment variables->文件圖標->±>輸入conda配置的Python環境路徑相關參數:參數是自己的Python環境,自己修改成自己的
D:\APP\Anaconda;
D:\APP\Anaconda\Library\mingw-w64\bin;
D:\APP\Anaconda\Library;
D:\APP\Anaconda\Lib\site-packages;
D:\APP\Anaconda\Scripts;
D:\APP\Anaconda\envs\torch\Library\bin;
結果顯示:
解決辦法:
file->Settings->搜索Python Console->Environment variables->輸入上面的參數:參數是自己的Python環境,自己修改成自己的
D:\APP\Anaconda;
D:\APP\Anaconda\Library\mingw-w64\bin;
D:\APP\Anaconda\Library;
D:\APP\Anaconda\Lib\site-packages;
D:\APP\Anaconda\Scripts;
D:\APP\Anaconda\envs\torch\Library\bin;
結果展示:
說明:這是一個機器學習實戰項目(附帶數據+代碼+文檔+視頻講