admin管理员组

文章数量:1666729

Pycharm Console 使用conda配置的Python环境时import报错解决

    • 1、错误背景
    • 2、错误原因
    • 3、问题解决
      • 3.1、py文件报错解决
      • 3.2 .console 报错解决

1、错误背景

自己使用的conda创建的python,安装了Pytorch环境,在jupyter上可以正常使用,命令行也可以正常使用,但是用Pycharm创建新项目时,使用conda创建的Python环境,在正常的py文件中import时报错,而且控制台也是import报错。

2、错误原因

因为在命令行中没错,在Pycharm中使用错误,则可能还是环境没有配置好,它报错是找不到模块,即它的环境目录没有放入进去,解决方法如下

3、问题解决

3.1、py文件报错解决

报错形式:

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;






结果显示:

3.2 .console 报错解决

解决办法:
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;

结果展示:

本文标签: 报错环境ConsolepycharmConda