vscode中提示NumPy版本1.22.3,但下载的是1.22.4

在cmd中查询numpy版本为1.22.4

img

但在vscode里运行时提示


发生异常: ImportError


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.9 from "D:\anaconda\envs\tensorflow\python.exe"
  * The NumPy version is: "1.22.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: 找不到指定的模块。
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。

During handling of the above exception, another exception occurred:

  File "E:\桌面1\yolo3-pytorch-master\utils\callbacks.py", line 4, in 
    import torch
ImportError: 

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.9 from "D:\anaconda\envs\tensorflow\python.exe"
  * The NumPy version is: "1.22.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: 找不到指定的模块。

请问应该怎么解决?

通过截图分析如下:

  • pip安装将numpy安装在了anaconda主目录下了,正如pip show numpy看到Location路径
  • 你在使用VSCode时候使用的应该是anaconda一个虚拟环境,而虚拟环境中安装的应该numpy 1.22.3

参考博文Anaconda-用conda创建python虚拟环境

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7495664
  • 这篇博客也不错, 你可以看下vscode中无法找到numpy的解决办法
  • 除此之外, 这篇博客: 《Python数据分析基础教程:NumPy学习指南(第2版)》笔记1:第一章 NumPy快速入门中的 1.4 动手实践:向量加法 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    假设我们需要对两个向量ab做加法。这里的向量即数学意义上的一维数组,随后我们将在第5章中学习如何用NumPy数组表示矩阵。向量a的取值为0~n的整数的平方,例如n3时,向量a014。向量b的取值为0~n的整数的立方,例如n3时,向量b018。用纯Python代码应该怎么写呢?我们先想一想这个问题,随后再与等价的NumPy代码进行比较。
    (1) 纯Python代码:

    def pythonsum(n):
        a = range(n)
        b = range(n)
        c = []
        
        for i in range(len(a)):
            a[i] = i ** 2
            b[i] = i ** 3
            c.append(a[i] + b[i])
            
        return c
    

    (2) 使用NumPy的代码:

    def `NumPy`sum(n):
        a = `NumPy`.arange(n) ** 2
        b = `NumPy`.arange(n) ** 3
        c = a + b
        return c
    

    注意, NumPysum()函数中没有使用for循环。同时,我们使用NumPy中的arange函数来创建包含0~n 的整数的NumPy数组。代码中的arange函数前面有一个前缀NumPy,表明该函数是从NumPy模块导入的。

    NumPy还是Python,得到的结果是一致的。不过,两者的输出结果在形式上有些差异。注意,NumPy sum()函数的输出不包含逗号。这是为什么呢?显然,我们使用的是NumPy数组,而非Python自身的列表。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^