Python ModuleNotFoundError: 没有名为“matplotlib”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49187042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:01:05  来源:igfitidea点击:

ModuleNotFoundError: No module named 'matplotlib'

pythonmacosmatplotlibpip

提问by Atticus Liu

I'm trying to run a python program that requires matplotlib, which I've already installed via pip. I am running Python 3.6 locally on my Mac, with my .bash_profile updated to reflect this. The import line in question is as seen below:

我正在尝试运行一个需要 matplotlib 的 python 程序,我已经通过 pip 安装了它。我在 Mac 上本地运行 Python 3.6,更新了我的 .bash_profile 以反映这一点。有问题的导入行如下所示:

import matplotlib.pyplot as plt

Below is the error message I see, as you can figure out from the subject line:

以下是我看到的错误消息,您可以从主题行中了解到:

ModuleNotFoundError: No module named 'matplotlib'

And here's what I see if I try pip install matplotlib:

如果我尝试,这就是我所看到的pip install matplotlib

Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: python-dateutil in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: pyparsing!=2.0.0,!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: pytz in /usr/local/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: six>=1.10 in /usr/local/lib/python3.6/site-packages (from matplotlib)

I've referenced a few other posts like thisand this, but without much luck. Am I overlooking an answer that I just didn't follow through with, or could it be something else? Your time is appreciated.

我已经参考了其他一些类似thisthis 的帖子,但运气不佳。我是否忽略了一个我没有遵循的答案,或者可能是其他问题?感谢您的时间。

回答by Eliethesaiyan

use pip3 install matplotlibto install matlplot lib. By default, pip will install those package for 2.7 as it the native one. using pip3 makes it specific for python 3, and make sure you have only one version of python 3

用于pip3 install matplotlib安装 matlplot lib。默认情况下,pip 将为 2.7 安装这些软件包,因为它是本机软件包。使用 pip3 使其特定于 python 3,并确保您只有一个版本的 python 3

回答by Narendra

Execute this from file this will work:-

从文件中执行此操作,这将起作用:-

import pip
pip.main(["install","matplotlib"])

this does not work

这不起作用