ModuleNotFoundError:没有名为' matplotlib'

时间:2018-03-09 05:18:05

标签: python macos matplotlib pip

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

import matplotlib.pyplot as plt

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

ModuleNotFoundError: No module named '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)

我引用了其他一些帖子,例如thisthis,但没有太多运气。我是否忽略了一个我没有完成的答案,或者它可能是其他的东西?感谢您的时间。

2 个答案:

答案 0 :(得分:8)

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

答案 1 :(得分:2)

从文件执行此功能: -

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