python - 导入 matplotlib 时出错,除非使用 anaconda

标签 python matplotlib ubuntu pip anaconda

我一直试图在我的计算机上运行一个使用 matplotlib 的程序,但是每当我运行它时,我都会收到以下错误:

ImportError: No module named 'matplotlib'
到目前为止,我已经尝试通过以下方式安装它:
pip install matplotlib
pip3 install matplotlib
python3 -m pip install matplotlib
sudo apt-get install python3-matplotlib
它设法工作的唯一方法是如果我通过 anaconda 安装它,但在我卸载它之后,它又开始显示错误消息。我正在使用 Ubuntu,并且我已经编辑了我的 .bashrc 文件以包含这些行:
export PYTHON=python3
alias python=python3
anaconda 是唯一解决方案的原因可能是什么?为什么卸载后它不能继续工作?

最佳答案

您可以尝试以下方法:
从终端运行:

python3 -m pip install matplotlib
如果这不起作用,请从终端尝试:
easy_install matplotlib
如果这也不起作用,请尝试打开 python 解释器(终端中的 python3)并在 python 解释器中运行以下命令:
import pip
pip.main(["install","matplotlib"])

关于python - 导入 matplotlib 时出错,除非使用 anaconda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67782839/

相关文章:

ubuntu - 由于 lxc 容器没有网络连接,OpenStack Ansible 部署失败

python - 如何将一个 Jupyter notebook 导入另一个

python - 在创建django时添加注册

python - 在 jupyter 笔记本中将 matplotlib 与 PyQt5 结合使用

python - 如何在 Python 的 matplotlib 中设置 'backend'?

parsing - Yacc 和 Lex "syntax error"

python - OpenCV 在 Linux 上的 python 与 anaconda 无法正常工作。收到未实现 cv2.imshow() 的错误

python - django:当 2 个字段具有相同值时过滤查询集

python - 某些数据未存储在数组中

python - Matplotlib:将图形另存为 iPython 笔记本中的文件