一、问题背景
在学习Python编程使用matplotlib
时,总是提示:ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
问题大致描述如下:
D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\Scripts\python.exe D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\part2\visable\tet.py
Traceback (most recent call last):
File "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\core\multiarray.py", line 10, in <module>
from . import overrides
File "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\core\overrides.py", line 8, 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 "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\__init__.py", line 159, in <module>
from numpy.__config__ import show as show_config
File "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\__config__.py", line 4, in <module>
from numpy.core._multiarray_umath import (
File "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\core\__init__.py", line 50, 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.10 from "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\Scripts\python.exe"
* The NumPy version is: "1.26.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'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\part2\visable\tet.py", line 1, in <module>
import matplotlib.pyplot as plt
File "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\matplotlib\__init__.py", line 184, in <module>
import numpy
File "D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\__init__.py", line 164, in <module>
raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
Process finished with exit code 1
二、解决思路
上述错误的原因是找不到matplotlib
所在包,类似于java中的找不到依赖,基于此种原因,有两个解决思路:
- 首先应该确保已经正确安装呆
matplotlib
包,这样才能正确导入包 - 确保项目所使用的Python编译器是我们本地安装的编译器
三、解决办法
3.1 安装matplotlib包
安装matplotlib依赖命令如下:文章来源:https://www.toymoban.com/news/detail-845376.html
python -m pip install --user matplotlib
3.2 检查项目编译器
检查项目所使用的编译器,这一点尤为重要也很容易被我们忽略,我就是因为这一步卡了一天: 我们需要使用的是本机安装的Python编译器,不能使用项目中的编译器,如下图红框所示:
文章来源地址https://www.toymoban.com/news/detail-845376.html
到了这里,关于Python提示‘ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath‘的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!