Brainvalley

人工知能と脳科学のアーカイブサイト。

サイドバー

最新情報を購読する

最新情報は、feedlyかRSSで購読できます。

脳科学・神経科学を網羅的に学ぶ必読書

カンデル神経科学

カンデル神経科学は、脳科学・神経科学分野のバイブル的存在。2014年4月に日本語版が出版され、英語や医学用語が得意でない方にも大変読みやすくなりました。脳科学、神経科学について学ぶなら絶対に持っておきたいおすすめの一冊。

最新記事

人工知能・脳科学エッセイ

書籍・セミナー・勉強会

オンライン大学

論文検索

研究者の採用・求人

Mac環境でPython3.4にmatplotlibをインストールする方法

Pythonのライブラリ、matplotlibをMac環境にインストールする手順です。

環境

手順

  • brewを使って、freetypelibpngをインストールします。libpngはfreetypeをインストールすると、自動的にインストールされます。
freetypeとlibpngをインストールする
% brew install freetype
 
==> Installing freetype dependency: libpng
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libpng-1.6.14.mountain_lion.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libpng-1.6.14.mountain_lion.bottle.tar.gz
🍺  /usr/local/Cellar/libpng/1.6.14: 17 files, 1.3M
==> Installing freetype
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/freetype-2.5.3_1.mountain_lion.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring freetype-2.5.3_1.mountain_lion.bottle.1.tar.gz
🍺  /usr/local/Cellar/freetype/2.5.3_1: 60 files, 2.6M
  • matplotlibをインストールします。
matplotlibをインストールする
pip3 install matplotlib
  • Wno-unused-resultが原因でインストールに失敗する場合は、下記のコマンドを実行します。
matplotlibをインストールする
sudo ARCHFLAGS=-Wno-unused-result pip3 install matplotlib

動作確認

下記のコマンドを実行し円グラフが表示されれば、正常にインストールが完了しています。

matplotlibの動作確認
python3 -c 'import matplotlib.pyplot as pyplot; pyplot.pie([1,2,3]); pyplot.show()'

インストールエラーが発生するときは

下記のようなエラーが発生するときは、freetypeやlibpngのインストールの有無、コンパイルオプションの有無などを確認しましょう。

% pip3 install matplotlib
 
Downloading/unpacking matplotlib
  Downloading matplotlib-1.4.2.tar.gz (50.1MB): 50.1MB downloaded
  Running setup.py (path:/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setup.py) egg_info for package matplotlib
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setup.py", line 155, in <module>
        result = package.check()
      File "/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setupext.py", line 962, in check
        min_version='2.3', version=version)
      File "/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setupext.py", line 446, in _check_for_pkg_config
        if (not is_min_version(version, min_version)):
      File "/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setupext.py", line 174, in is_min_version
        return found_version >= expected_version
      File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/version.py", line 76, in __ge__
        c = self._cmp(other)
      File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/version.py", line 343, in _cmp
        if self.version < other.version:
    TypeError: unorderable types: str() < int()
    ============================================================================
    Edit setup.cfg to change the build options
 
    BUILDING MATPLOTLIB
                matplotlib: yes [1.4.2]
                    python: yes [3.4.2 (default, Oct 19 2014, 17:50:17)  [GCC
                            4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)]]
                  platform: yes [darwin]
 
    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.9.1]
                       six: yes [six was not found.]
                  dateutil: yes [dateutil was not found. It is required for date
                            axis support. pip/easy_install may attempt to
                            install it after matplotlib.]
                      pytz: yes [pytz was not found. pip will attempt to install
                            it after matplotlib.]
                   tornado: yes [tornado was not found. It is required for the
                            WebAgg backend. pip/easy_install may attempt to
                            install it after matplotlib.]
                 pyparsing: yes [pyparsing was not found. It is required for
                            mathtext support. pip/easy_install may attempt to
                            install it after matplotlib.]
                     pycxx: yes [Official versions of PyCXX are not compatible
                            with matplotlib on Python 3.x, since they lack
                            support for the buffer object.  Using local copy]
                    libagg: yes [pkg-config information for 'libagg' could not
                            be found. Using local copy.]
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
 
  File "<string>", line 17, in <module>
 
  File "/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setup.py", line 155, in <module>
 
    result = package.check()
 
  File "/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setupext.py", line 962, in check
 
    min_version='2.3', version=version)
 
  File "/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setupext.py", line 446, in _check_for_pkg_config
 
    if (not is_min_version(version, min_version)):
 
  File "/private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib/setupext.py", line 174, in is_min_version
 
    return found_version >= expected_version
 
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/version.py", line 76, in __ge__
 
    c = self._cmp(other)
 
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/version.py", line 343, in _cmp
 
    if self.version < other.version:
 
TypeError: unorderable types: str() < int()
 
============================================================================
 
Edit setup.cfg to change the build options
 
 
 
BUILDING MATPLOTLIB
 
            matplotlib: yes [1.4.2]
 
                python: yes [3.4.2 (default, Oct 19 2014, 17:50:17)  [GCC
 
                        4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)]]
 
              platform: yes [darwin]
 
 
 
REQUIRED DEPENDENCIES AND EXTENSIONS
 
                 numpy: yes [version 1.9.1]
 
                   six: yes [six was not found.]
 
              dateutil: yes [dateutil was not found. It is required for date
 
                        axis support. pip/easy_install may attempt to
 
                        install it after matplotlib.]
 
                  pytz: yes [pytz was not found. pip will attempt to install
 
                        it after matplotlib.]
 
               tornado: yes [tornado was not found. It is required for the
 
                        WebAgg backend. pip/easy_install may attempt to
 
                        install it after matplotlib.]
 
             pyparsing: yes [pyparsing was not found. It is required for
 
                        mathtext support. pip/easy_install may attempt to
 
                        install it after matplotlib.]
 
                 pycxx: yes [Official versions of PyCXX are not compatible
 
                        with matplotlib on Python 3.x, since they lack
 
                        support for the buffer object.  Using local copy]
 
                libagg: yes [pkg-config information for 'libagg' could not
 
                        be found. Using local copy.]
 
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /private/var/folders/dy/ffm11v7n3_16xbw15wlbxwbm0000gn/T/pip_build_zero/matplotlib
Storing debug log for failure in /Users/zero/.pip/pip.log

関連