【发布时间】:2022-06-12 18:11:35
【问题描述】:
我在做什么:
我正在尝试导入 numpy:
import numpy
但我收到以下错误:
Exception has occurred: 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 "C:\Users\jack_l\AppData\Local\Programs\Python\Python39\python.exe"
* The NumPy version is: "1.22.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
我浏览了帮助网站,但找不到任何有用的东西(我尝试了所有方法,但如果我尝试了所有方法正确:/)。
我做了什么以及我发现了什么:
- 我目前在我的设备上安装了两个版本的 python(3.9 和 3.10),我认为这可能会导致问题。
- 我正在使用 VSCode,我的解释器在 Python 3.9.13 上(图 1),但是当我在 PowerShell 终端中执行
py --version时,它说我在 Python 3.10.4 上(图 2) - 当我打印
os.environ.get('PYTHONPATH')时,它给了我c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages,我认为这是不对的,但我不知道如何解决。
图片1:
图 2:
完整的错误回溯:
Traceback (most recent call last):
File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\core\__init__.py", line 23, in <module>
from . import multiarray
File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\core\multiarray.py", line 10, in <module>
from . import overrides
File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\core\overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\jack_l\Documents\CAR_MIX\mega.py", line 8, in <module>
import numpy as np
File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\__init__.py", line 144, in <module>
from . import core
File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\numpy\core\__init__.py", line 49, in <module>
raise ImportError(msg)
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 "C:\Users\jack_l\AppData\Local\Programs\Python\Python39\python.exe"
* The NumPy version is: "1.22.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
【问题讨论】:
-
回溯表明您正在使用 Python 3.10 来实际执行您的脚本。我不确定为什么 Numpy 说你使用的是 3.9。
-
@MattDMo 如何更改它以便使用 Python 3.9 执行我的脚本?
-
我不怎么用VSCode,所以不知道如何正确配置。您可以尝试使用 3.9 创建一个新的 virtualenv,安装 Numpy 和其中的任何其他依赖项,然后在 VSCode 中选择 virtualenv 并查看是否有效。
-
在 VSCode 中,如果您单击显示“Python 3.9”的窗口,您可以将其更改为您需要的任何内容
-
我刚刚卸载了我的两个版本的 Python 并重新安装了 Python 3.9,它运行正常,哈哈。好 ole 重置
标签: python python-3.x numpy visual-studio-code importerror