当前位置:   article > 正文

Conda新建环境后import numpy时出现的问题_conda新建环境import解析失败

conda新建环境import解析失败

问题由来

本人伪程序员一枚,某日心血来潮,想使用conda+VScode的方案应对日后的python编程任务,不幸的是,在新建了环境并在VScode中选择了对应的解释器后,使用import numpy总是出现如下报错

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.9 from "D:\ProgramData\Miniconda3\envs\test\python.exe"
  * The NumPy version is: "1.20.3"

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 while importing _multiarray_umath: 找不到指定的模块。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

注意到VScode中使用的还是默认的Powershell,而在CMD中先激活环境再使用import numpy则可以正常运行

问题解决

查阅了大量网页资料,经试验使用pip而非conda进行卸载和重装确实可以解决问题,但对于包的管理终究是不便的,报错中https://numpy.org/devdocs/user/troubleshooting-importerror.html指示我们去VSCode support寻求帮助,其中明确写道

  • Conda environments can’t be automatically activated in the VS Code Integrated Terminal if the default shell is set to PowerShell. To change the shell, see Integrated terminal - Configuration.

结合之前观察到的在CMD中可正常运行的现象,可进行如下设置
在这里插入图片描述

之后选择在终端中运行python文件时可有效激活所选的虚拟环境。

说明

该报错对应的原因较为复杂,本人所遇情况较为简单,希望可以为遇到相似问题的朋友提供参考。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/595843
推荐阅读
相关标签
  

闽ICP备14008679号