ImportError:没有名为pyplot的模块(即使在安装matplotlib之后)

时间:2016-12-19 23:40:40

标签: python python-2.7 matplotlib

我正在尝试像这样导入matplotlib:

import matplotlib.pyplot as plt

为此我已经安装了matplotlib。

python -m pip install -U pip setuptools
python -m pip install matplotlib

虽然来自the examplesbasic_example.py工作,但它突然停止与matplotlib的所有其他文件一起运行,给出了以下错误:

File "matplotlib.py", line 2, in <module>
  import matplotlib.pyplot as plt # pyplot module.
ImportError: No module named pyplot`

我试图检查模块是否仍在那里,似乎是。什么可能是错的?

Requirement already satisfied: matplotlib in c:\python27\lib\site-packages
Requirement already satisfied: numpy>=1.6 in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: python-dateutil in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: cycler in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,>=1.5.6 in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: pytz in c:\python27\lib\site-packages (from matplotlib)
Requirement already satisfied: six>=1.5 in c:\python27\lib\site-packages (from python-dateutil->matplotlib)`

我使用的是Windows和Python 2.7。

1 个答案:

答案 0 :(得分:5)

Python 2.7在进入已安装的软件包之前首先尝试在当前工作目录中查找模块,因为您将测试文件命名为#34; matplotlib.py&#34;,它会将其解释为matplotlib软件包。将您的测试文件重命名为其他内容,它应该没问题