|
一、问题背景 在学习Python编程使用matplotlib时,总是提示:ModuleNotFoundError:Nomodulenamed'numpy.core._multiarray_umath'问题大致描述如下:D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\Scripts\python.exeD:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\part2\visable\tet.pyTraceback(mostrecentcalllast):File"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\core\__init__.py",line24,infrom.importmultiarrayFile"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\core\multiarray.py",line10,infrom.importoverridesFile"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\core\overrides.py",line8,infromnumpy.core._multiarray_umathimport(ModuleNotFoundError:Nomodulenamed'numpy.core._multiarray_umath'Duringhandlingoftheaboveexception,anotherexceptionoccurred:Traceback(mostrecentcalllast):File"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\__init__.py",line159,infromnumpy.__config__importshowasshow_configFile"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\__config__.py",line4,infromnumpy.core._multiarray_umathimport(File"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\core\__init__.py",line50,inraiseImportError(msg)ImportError:IMPORTANTLEASEREADTHISFORADVICEONHOWTOSOLVETHISISSUE!ImportingthenumpyC-extensionsfailed.Thiserrorcanhappenformanyreasons,oftenduetoissueswithyoursetuporhowNumPywasinstalled.Wehavecompiledsomecommonreasonsandtroubleshootingtipsat:https://numpy.org/devdocs/user/troubleshooting-importerror.htmlPleasenoteandcheckthefollowing:*ThePythonversionisython3.10from"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\Scripts\python.exe"*TheNumPyversionis:"1.26.4"andmakesurethattheyaretheversionsyouexpect.Pleasecarefullystudythedocumentationlinkedaboveforfurtherhelp.Originalerrorwas:Nomodulenamed'numpy.core._multiarray_umath'Theaboveexceptionwasthedirectcauseofthefollowingexception:Traceback(mostrecentcalllast):File"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\part2\visable\tet.py",line1,inimportmatplotlib.pyplotaspltFile"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\matplotlib\__init__.py",line184,inimportnumpyFile"D:\WorkSpace\PythonWorkSpace\Python编程-从入门到实践\venv\lib\site-packages\numpy\__init__.py",line164,inraiseImportError(msg)fromeImportError:Errorimportingnumpy:youshouldnottrytoimportnumpyfromitssourcedirectory;pleaseexitthenumpysourcetree,andrelaunchyourpythoninterpreterfromthere.Processfinishedwithexitcode11234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556二、解决思路 上述错误的原因是找不到matplotlib所在包,类似于java中的找不到依赖,基于此种原因,有两个解决思路:首先应该确保已经正确安装呆matplotlib包,这样才能正确导入包确保项目所使用的Python编译器是我们本地安装的编译器三、解决办法3.1安装matplotlib包 安装matplotlib依赖命令如下:python-mpipinstall--usermatplotlib13.2检查项目编译器 检查项目所使用的编译器,这一点尤为重要也很容易被我们忽略,我就是因为这一步卡了一天:我们需要使用的是本机安装的Python编译器,不能使用项目中的编译器,如下图红框所示:
|
|