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中可正常运行的现象,可进行如下设置
在这里插入图片描述

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

说明

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值