Conda新建环境后import numpy时出现的问题

问题由来

本人伪程序员一枚,某日心血来潮,想使用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: 找不到指定的模块。

注意到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中可正常运行的现象,可进行如下设置

Conda新建环境后import numpy时出现的问题

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

; 说明

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

Original: https://blog.csdn.net/qq_43402219/article/details/120404090
Author: MIUNJV
Title: Conda新建环境后import numpy时出现的问题

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/761413/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球