2016-12-19 165 views
1

我試圖導入matplotlib像這樣:導入錯誤:沒有模塊名爲pyplot(即使安裝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。

+0

當你運行'import matplotlib'時會發生什麼? –

+0

爲什麼在''ImportError:沒有名爲pyplot的模塊'''o_o – moogle

+0

@TedPetrou同樣的錯誤中有重音符。 import matplotlib.pyplot as plt#pyplot module。 ImportError:沒有名爲pyplot的模塊 – stochastiker

回答

5

在進入已安裝的軟件包之前,Python 2.7會先嚐試在當前工作目錄中找到模塊,因爲您已將測試文件命名爲「matplotlib.py」,它會將其解釋爲matplotlib軟件包。將你的測試文件重命名爲其他東西,它應該沒問題

+0

是的。現在工作。非常感謝。 – stochastiker

相關問題