本文介绍了在OS X Lion 10.7.4和Python 3.2.2上安装MatPlotLib 1.2.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我问了一个有关在同一系统上安装numpy的问题.幸运的是,我设法自己解决了一个问题,但不幸的是,现在我被困在尝试安装matplotlib的过程中.

I asked a question a couple of days ago regarding installing numpy on the same system. Thankfully, I managed to solve that one myself but unfortunately I am now stuck trying to install matplotlib.

我首先尝试了当前的分布式版本,但是没有运气,所以我认为我将下载git存储库并尝试一下.我已经走了这么远:

I first of all tried the current distributed version but had no luck with that so I thought i would download the git repository and try that. I have got this far:

  • 更改了make.osx文件,使其可以在Python 3中运行:
    • import urllib-> import urllib.request
    • urllib.urlretrieve()-> urllib.request.urlretrieve()
    • changed the make.osx file so that it will work in Python 3:
      • import urllib -> import urllib.request
      • urllib.urlretrieve() -> urllib.request.urlretrieve()

      即使在那之后,我仍然有一个问题,那就是找不到freetype2标头.我四处搜寻,发现可以通过在setupext.py中编辑一行来解决此问题:

      Even after that I still had a problem with it not finding the freetype2 headers. I googled around and discovered that I could solve this by editing a line in setupext.py:

      • 'darwin' : [],-> 'darwin' : ['/usr/local'],
      • 'darwin' : [], -> 'darwin' : ['/usr/local'],

      但是,使用make.osx文件时,我仍然收到错误消息.这是我从终端中调用文件的方式:

      However, I still get an error message when using the make.osx file. Here is how I am calling the file from Terminal:

      • sudo make -f make.osx PREFIX=/usr/local PYVERSION=3.2 fetch deps mpl_build mpl_install

      我了解到Python 3尚未正式支持matplotlib,但我认为也许某个地方至少有人设法将其编译/安装?

      I realise that matplotlib isn't officially supported on Python 3 yet but I thought that maybe someone somewhere as at least managed to get it to compile/install?

      任何帮助将不胜感激,

      亚当.

      我已包含以下错误:

      basedirlist is: ['/usr/local']
      ============================================================================
      BUILDING MATPLOTLIB
                  matplotlib: 1.2.x
                      python: 3.2.2 (v3.2.2:137e45f15c0b, Sep  3 2011, 17:28:59)
                              [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
                    platform: darwin
      
      REQUIRED DEPENDENCIES
                       numpy: 1.6.2rc1
                   freetype2: found, but unknown version (no pkg-config)
      
      OPTIONAL BACKEND DEPENDENCIES
                      libpng: found, but unknown version (no pkg-config)
                     Tkinter: Tkinter: version not identified, Tk: 8.5, Tcl: 8.5
                        Gtk+: no
                              * Building for Gtk+ requires pygtk; you must be able
                              * to "import gtk" in your build/install environment
             Mac OS X native: yes
                          Qt: no
                         Qt4: Qt: 4.7.4, PyQt4: 4.8.6
                      PySide: no
                       Cairo: no
      
      OPTIONAL DATE/TIMEZONE DEPENDENCIES
                    datetime: present, version unknown
                    dateutil: matplotlib will provide
                        pytz: matplotlib will provide
      adding pytz
      
      OPTIONAL USETEX DEPENDENCIES
                      dvipng: no
                 ghostscript: /bin/sh: gs: command not found
                       latex: no
      
      [Edit setup.cfg to suppress the above messages]
      ============================================================================
      pymods ['pylab']
      packages ['matplotlib', 'matplotlib.backends', 'matplotlib.backends.qt4_editor', 'matplotlib.projections', 'matplotlib.testing', 'matplotlib.testing.jpl_units', 'matplotlib.tests', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid', 'mpl_toolkits.axes_grid1', 'mpl_toolkits.axisartist', 'matplotlib.sphinxext', 'matplotlib.tri', 'matplotlib.delaunay', 'pytz', 'dateutil', 'dateutil.zoneinfo']
      running build
      running build_py
      copying lib/matplotlib/mpl-data/matplotlibrc -> build/lib.macosx-10.6-intel-3.2/matplotlib/mpl-data
      copying lib/matplotlib/mpl-data/matplotlib.conf -> build/lib.macosx-10.6-intel-3.2/matplotlib/mpl-data
      
      running build_ext
      building 'matplotlib.ft2font' extension
      gcc-4.2 -DNDEBUG -g -O3 -arch i386 -arch x86_64 -I/usr/local/include -I/usr/local/include/freetype2 -isysroot /Developer/SDKs/MacOSX10.6.sdk -DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -DPYCXX_PYTHON_2TO3=1 -I/usr/local/include -I/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include -I/usr/local/include -I. -I/usr/local/include/freetype2 -I/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/freetype2 -I/usr/local/include/freetype2 -I./freetype2 -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m -c src/ft2font.cpp -o build/temp.macosx-10.6-intel-3.2/src/ft2font.o
      In file included from /Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m/bytearrayobject.h:9,
                       from /Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m/Python.h:73,
                       from ./CXX/WrapPython.h:58,
                       from ./CXX/Extensions.hxx:37,
                       from src/ft2font.h:6,
                       from src/ft2font.cpp:3:
      /Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
      In file included from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/iosfwd:45,
                       from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/bits/stl_algobase.h:70,
                       from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/bits/char_traits.h:46,
                       from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/string:47,
                       from ./CXX/Python3/Exception.hxx:47,
                       from ./CXX/Python3/Objects.hxx:45,
                       from ./CXX/Python3/Extensions.hxx:52,
                       from ./CXX/Extensions.hxx:42,
                       from src/ft2font.h:6,
                       from src/ft2font.cpp:3:
      /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/i686-apple-darwin11/bits/c++locale.h: In function ‘int std::__convert_from_v(int* const&, char*, int, const char*, ...)’:
      /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/i686-apple-darwin11/bits/c++locale.h:77: error: ‘va_start’ was not declared in this scope
      /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/i686-apple-darwin11/bits/c++locale.h:85: error: ‘va_end’ was not declared in this scope
      In file included from /Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m/bytearrayobject.h:9,
                       from /Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m/Python.h:73,
                       from ./CXX/WrapPython.h:58,
                       from ./CXX/Extensions.hxx:37,
                       from src/ft2font.h:6,
                       from src/ft2font.cpp:3:
      /Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
      In file included from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/iosfwd:45,
                       from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/bits/stl_algobase.h:70,
                       from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/bits/char_traits.h:46,
                       from /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/string:47,
                       from ./CXX/Python3/Exception.hxx:47,
                       from ./CXX/Python3/Objects.hxx:45,
                       from ./CXX/Python3/Extensions.hxx:52,
                       from ./CXX/Extensions.hxx:42,
                       from src/ft2font.h:6,
                       from src/ft2font.cpp:3:
      /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/i686-apple-darwin11/x86_64/bits/c++locale.h: In function ‘int std::__convert_from_v(int* const&, char*, int, const char*, ...)’:
      /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/i686-apple-darwin11/x86_64/bits/c++locale.h:77: error: ‘va_start’ was not declared in this scope
      /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/i686-apple-darwin11/x86_64/bits/c++locale.h:85: error: ‘va_end’ was not declared in this scope
      lipo: can't figure out the architecture type of: /var/tmp//ccafJH1l.out
      error: command 'gcc-4.2' failed with exit status 1
      make: *** [mpl_build] Error 1
      

      推荐答案

      好吧...我认为已经成功安装了 matplotlib ...

      Okay...I think have managed to get matplotlib to install now...

      1. 首先,您需要安装 numpy .我在另一篇文章中有执行此操作的说明:

      1. First of all you need to install numpy. I have instructions to do this on another post: install numpy

      现在打开 Terminal 并克隆 matplotlib 的git存储库(假设您已安装git):

      Now open Terminal and clone the git repository for matplotlib (assumes you have git installed):

      • git clone git://github.com/matplotlib/matplotlib.git(这可能需要一段时间)
      • git clone git://github.com/matplotlib/matplotlib.git (this might take a while)

      克隆完成后,在 Finder

      在您的用户文件夹中,打开matplotlib目录

      In your user folder open the matplotlib directory

      有一个名为"make.osx"的文件,可通过 TextEdit (或类似文件)

      There is a file called `make.osx' open this with TextEdit (or similar)

      更改以下几行:

      • MACOSX_DEPLOYMENT_TARGET=10.6
      • OSX_SDK_VER=10.6
      • MACOSX_DEPLOYMENT_TARGET=10.6
      • OSX_SDK_VER=10.6

      收件人:

      • MACOSX_DEPLOYMENT_TARGET=10.7
      • OSX_SDK_VER=10.7
      • MACOSX_DEPLOYMENT_TARGET=10.7
      • OSX_SDK_VER=10.7

      更改以下几行:

      • ${PYTHON} -c 'import urllib; urllib.urlretrieve("${ZLIBURL}", "${ZLIBFILE}")' &&\${PYTHON} -c 'import urllib; urllib.urlretrieve("${PNGURL}", "${PNGFILE}")' &&\${PYTHON} -c 'import urllib; urllib.urlretrieve("${FREETYPEURL}", "${FREETYPEFILE}")'
      • ${PYTHON} -c 'import urllib; urllib.urlretrieve("${ZLIBURL}", "${ZLIBFILE}")' &&\${PYTHON} -c 'import urllib; urllib.urlretrieve("${PNGURL}", "${PNGFILE}")' &&\${PYTHON} -c 'import urllib; urllib.urlretrieve("${FREETYPEURL}", "${FREETYPEFILE}")'

      收件人:

      • ${PYTHON} -c 'import urllib.request; urllib.request.urlretrieve("${ZLIBURL}", "${ZLIBFILE}")' &&\${PYTHON} -c 'import urllib.request; urllib.request.urlretrieve("${PNGURL}", "${PNGFILE}")' &&\${PYTHON} -c 'import urllib.request; urllib.request.urlretrieve("${FREETYPEURL}", "${FREETYPEFILE}")'
      • ${PYTHON} -c 'import urllib.request; urllib.request.urlretrieve("${ZLIBURL}", "${ZLIBFILE}")' &&\${PYTHON} -c 'import urllib.request; urllib.request.urlretrieve("${PNGURL}", "${PNGFILE}")' &&\${PYTHON} -c 'import urllib.request; urllib.request.urlretrieve("${FREETYPEURL}", "${FREETYPEFILE}")'

      保存更改

      空闲

      找到行'darwin' : [],并将其更改为'darwin' : ['/usr/local'],

      保存文件

      再次打开终端,然后输入以下内容:

      Open Terminal again and type the following:

      • sudo make -f make.osx PREFIX=/usr/local PYVERSION=3.2 fetch deps mpl_build mpl_install

      一段时间后,应在以下目录中安装matplotlib:

      After some time matplotlib should be installed in the following directory:

      • /usr/local/lib/Python3.2/site-packages/

      打开以上目录以及以下目录:

      Open the above directory and also the following directory:

      • /Library/Python/3.2/site-packages/

      将以下目录从/usr/local/lib/Python3.2/site-packages/复制/移动到/Library/Python/3.2/site-packages/:

      Copy/move the following directories from /usr/local/lib/Python3.2/site-packages/ to /Library/Python/3.2/site-packages/:

      • dateutil
      • matplotlib
      • mpl_toolkits
      • dateutil
      • matplotlib
      • mpl_toolkits

      matplotlib 现在应该已安装

      如果打开空闲并键入import matplotlib,则不会返回错误

      If you open idle and type import matplotlib it shouldn't return an error

      我尝试了matplotlib/examples/user_interfaces/embedding_in_qt4_wtoolbar.py文件,看来工作正常

      I tried out the matplotlib/examples/user_interfaces/embedding_in_qt4_wtoolbar.py file and it seems works fine

      希望其他人觉得这有用!

      Hope someone else finds this useful!

      再次感谢您的帮助,

      亚当.

      这篇关于在OS X Lion 10.7.4和Python 3.2.2上安装MatPlotLib 1.2.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 21:51