[英]matplotlib installed - ModuleNotFoundError: No module named 'matplotlib'
I installed matplotlib.我安装了 matplotlib。
But when i try to import it into my project import matplotlib.pyplot as plt但是当我尝试将它导入到我的项目中时,将 matplotlib.pyplot 作为 plt
it say ModuleNotFoundError: No module named 'matplotlib'它说 ModuleNotFoundError: No module named 'matplotlib'
pip list gives me: matplotlib 3.2.1 pip 列表给了我:matplotlib 3.2.1
I am using Atom我正在使用原子
I tried reinstalling matplotlib several times and every solution i could find on google, nothing seems to work.我尝试重新安装 matplotlib 几次,我可以在谷歌上找到的每个解决方案,似乎没有任何效果。
A lot of things can make your code not to find the module, one of the common problem is having multiple python versions installed on your computer.很多事情都会使您的代码找不到模块,其中一个常见问题是您的计算机上安装了多个 python 版本。 Using a virtual environment to manage the project will help fix such problems on your project.使用虚拟环境管理项目将有助于解决项目中的此类问题。
On your project directory, create a virtual environment with venv在您的项目目录中,使用 venv 创建一个虚拟环境python3 -m venv workspace
workspace is the name of the environment, you can give it any name you want工作区是环境的名称,你可以给它任何你想要的名字
Activate the virtual environment激活虚拟环境
On PC use this code在 PC 上使用此代码workspace\Scripts\activate.bat
On Mac/Linux在 Mac/Linux 上source venv/bin/activate
Install matplotlib in the virtual environment and run your code在虚拟环境中安装 matplotlib 并运行你的代码
When you are done you could deactivate the environment with this code完成后,您可以使用此代码停用环境deactivate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.