Hope is a Dream. Dream is a Hope.

非公開ブログは再開しました。

忙しいのに、matplotlibがwindowsにインストールできない初心者のためのエラー対処メモ

matplotlibをwindowsにインストールする。

f:id:hope_is_dream:20141118083300j:plain

僕の環境 python2.7 32bit

matplotlibのダウンロード

http://sourceforge.net/projects/matplotlib/?source=typ_redirect

matplotlib-1.4.2.win32-py2.7.exe

インストール後

python
import matplotlib

恐らくエラーが出てこちらのページを調べていると思うので、

それぞれに関して以下のエラーを見てください。

忙しい人のために結論から話すと、

pip install numpy python-dateutil pytz pyparsing six --force-reinstall --upgrade

これで対処できると思います。

こちらのコードでは、numpy, python-dateutil, pytz, pyparsing, sixという5つのモジュールをpipを使って強制インストール、再インストールをしています。

必要に応じて利用してください。

参考元 python - ImportError: matplotlib requires dateutil - Stack Overflow

f:id:hope_is_dream:20141118083310j:plain

成功するとグラフがでます。

サンプルコード

http://matplotlib.org/examples/animation/animate_decay.html

残り記事はそれぞれを個別にインストールしているだけになります。

ImportError: No module named six

C:\pytest>python
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 105, in <module> import six
ImportError: No module named six

sixが足りないのさ。

pipで入れてあげます。

pip install six

ImportError: matplotlib requires dateutil

C:\pytest>python
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 116, in <mod
ule>
    raise ImportError("matplotlib requires dateutil")
ImportError: matplotlib requires dateutil
>>>

dateutilが足りないのさ。

pipで入れてあげます。

pip install python-dateutil

ImportError: matplotlib requires pyparsing

C:\pytest>python pyscript2.py
Traceback (most recent call last):
  File "pyscript2.py", line 2, in <module>
    import matplotlib.pyplot as plt
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 140, in <mod
ule>
    raise ImportError("matplotlib requires pyparsing")
ImportError: matplotlib requires pyparsing

pip install pyparsing

ImportError: matplotlib requires `pytz'

これも同様に

pip install pytz

その他参考にした資料

http://stackoverflow.com/questions/21222458/python-error-importerror-no-module-named-six

Windowsにpython環境をインストールする方法 - Hope is a Dream. Dream is a Hope.

手軽に科学技術計算のためにWindowsでPython を始めたい人へ。( 計算環境構築編 ) - Hope is a Dream. Dream is a Hope.