2016-02-29 95 views
0

时遇到问题我已经从here下载并运行ez_setup.py。然后我跑了easy_install -m matplotlib给了我下面的墙文,我不明白。我在安装matplotlib

➜ ~ easy_install -m matplotlib 
Searching for matplotlib 
Reading https://pypi.python.org/simple/matplotlib/ 
Best match: matplotlib 1.5.1 
Downloading https://pypi.python.org/packages/source/m/matplotlib/matplotlib-1.5.1.tar.gz#md5=f51847d8692cb63df64cd0bd0304fd20 
Processing matplotlib-1.5.1.tar.gz 
Writing /var/folders/zl/ryqgsffd7nq918q0vxhltw500000gn/T/easy_install-dkok1o6z/matplotlib-1.5.1/setup.cfg 
Running matplotlib-1.5.1/setup.py -q bdist_egg --dist-dir /var/folders/zl/ryqgsffd7nq918q0vxhltw500000gn/T/easy_install-dkok1o6z/matplotlib-1.5.1/egg-dist-tmp-3brr2ngu 
============================================================================ 
Edit setup.cfg to change the build options 

BUILDING MATPLOTLIB 
      matplotlib: yes [1.5.1] 
       python: yes [3.5.1 (default, Feb 26 2016, 15:40:09) [GCC 
         4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]] 
       platform: yes [darwin] 

REQUIRED DEPENDENCIES AND EXTENSIONS 
       numpy: yes [version 1.10.4] 
       dateutil: yes [using dateutil version 2.4.2] 
        pytz: yes [using pytz version 2015.7] 
       cycler: yes [using cycler version 0.10.0] 
       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 [using pyparsing version 2.1.0] 
       libagg: yes [pkg-config information for 'libagg' could not 
         be found. Using local copy.] 
       freetype: yes [version 2.5.5] 
        png: yes [version 1.6.16] 
       qhull: yes [pkg-config information for 'qhull' could not be 
         found. Using local copy.] 

OPTIONAL SUBPACKAGES 
      sample_data: yes [installing] 
       toolkits: yes [installing] 
       tests: yes [nose 0.11.1 or later is required to run the 
         matplotlib test suite. Please install it with pip or 
         your preferred tool to run the test suite/using 
         unittest.mock] 
     toolkits_tests: yes [nose 0.11.1 or later is required to run the 
         matplotlib test suite. Please install it with pip or 
         your preferred tool to run the test suite/using 
         unittest.mock] 

OPTIONAL BACKEND EXTENSIONS 
       macosx: yes [installing, darwin] 
       qt5agg: no [PyQt5 not found] 
       qt4agg: no [PySide not found; PyQt4 not found] 
       gtk3agg: no [Requires pygobject to be installed.] 
      gtk3cairo: no [Requires cairocffi or pycairo to be installed.] 
       gtkagg: no [Requires pygtk] 
       tkagg: no [The C/C++ header for Tk (tk.h) could not be 
         found. You may need to install the development 
         package.] 
       wxagg: no [requires wxPython] 
        gtk: no [Requires pygtk] 
        agg: yes [installing] 
       cairo: no [cairocffi or pycairo not found] 
      windowing: no [Microsoft Windows only] 

OPTIONAL LATEX DEPENDENCIES 
       dvipng: no 
      ghostscript: yes [version 9.16] 
       latex: no 
       pdftops: no 

OPTIONAL PACKAGE DATA 
        dlls: no [skipping due to configuration] 

UPDATING build/lib.macosx-10.11-x86_64-3.5/matplotlib/_version.py 
set build/lib.macosx-10.11-x86_64-3.5/matplotlib/_version.py to '1.5.1' 
extern/agg24-svn/src/agg_curves.cpp:24:18: warning: unused variable 'curve_distance_epsilon' [-Wunused-const-variable] 
    const double curve_distance_epsilon     = 1e-30; 
       ^
1 warning generated. 
extern/agg24-svn/src/agg_curves.cpp:24:18: warning: unused variable 'curve_distance_epsilon' [-Wunused-const-variable] 
    const double curve_distance_epsilon     = 1e-30; 
       ^
1 warning generated. 
extern/qhull/geom2.c:996:5: warning: code will never be executed [-Wunreachable-code] 
    qh_fprintf(qh ferr, 6011, "qhull error: floating point constants in user.h are wrong\n\ 
    ^~~~~~~~~~ 
extern/qhull/geom2.c:993:23: note: silence by adding parentheses to mark code as explicitly dead 
    && REALmax > 0.0 && -REALmax < 0.0) 
        ^
         /* DISABLES CODE */ () 
1 warning generated. 
extern/qhull/global.c:1524:5: warning: code will never be executed [-Wunreachable-code] 
    qh_fprintf(qh ferr, 7039, "qhull warning: real epsilon, %2.2g, is probably too large for joggle('QJn')\nRecompile with double pr... 
    ^~~~~~~~~~ 
1 warning generated. 
src/_macosx.m:1919:21: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare] 
    for (ih = 0; ih < meshHeight; ih++) 
       ~~^~~~~~~~~~~ 
src/_macosx.m:1921:25: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare] 
     for (iw = 0; iw < meshWidth; iw++, i++) 
        ~~^~~~~~~~~~ 
src/_macosx.m:3743:17: warning: null passed to a callee that requires a non-null argument [-Wnonnull] 
    data = [rep representationUsingType:filetype properties:nil]; 
       ^           ~~~ 
src/_macosx.m:4602:19: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare] 
    for (i = 0; i < n; i++) 
       ~^~ 
4 warnings generated. 
extern/agg24-svn/src/agg_curves.cpp:24:18: warning: unused variable 'curve_distance_epsilon' [-Wunused-const-variable] 
    const double curve_distance_epsilon     = 1e-30; 
       ^
1 warning generated. 
extern/agg24-svn/src/agg_curves.cpp:24:18: warning: unused variable 'curve_distance_epsilon' [-Wunused-const-variable] 
    const double curve_distance_epsilon     = 1e-30; 
       ^
1 warning generated. 
creating /usr/local/lib/python3.5/site-packages/matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg 
Extracting matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg to /usr/local/lib/python3.5/site-packages 

Installed /usr/local/lib/python3.5/site-packages/matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg 
Because this distribution was installed --multi-version, before you can 
import modules from this package in an application, you will need to 
'import pkg_resources' and then use a 'require()' call similar to one of 
these examples, in order to select the desired version: 

    pkg_resources.require("matplotlib") # latest installed version 
    pkg_resources.require("matplotlib==1.5.1") # this exact version 
    pkg_resources.require("matplotlib>=1.5.1") # this version or higher 

Processing dependencies for matplotlib 
Finished processing dependencies for matplotlib 

如果我现在尝试导入matplotlib我得到

>>> import matplotlib.pyplot as plt 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named 'matplotlib' 

所以后来我尝试使用pkg_resources通过上面的输出的建议,并得到

➜ ~ python3 
Python 3.5.1 (default, Feb 26 2016, 15:40:09) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import pkg_resources 
>>> pkg_resources.require("matplotlib==1.5.1") 
[matplotlib 1.5.1 (/usr/local/lib/python3.5/site-packages/matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg), pyparsing 2.1.0 (/usr/local/lib/python3.5/site-packages), cycler 0.10.0 (/usr/local/lib/python3.5/site-packages), pytz 2015.7 (/usr/local/lib/python3.5/site-packages), python-dateutil 2.4.2 (/usr/local/lib/python3.5/site-packages), numpy 1.10.4 (/usr/local/lib/python3.5/site-packages), six 1.10.0 (/usr/local/lib/python3.5/site-packages), six 1.10.0 (/usr/local/lib/python3.5/site-packages)] 
>>> import matplotlib.pyplot as plt 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python3.5/site-packages/matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg/matplotlib/__init__.py", line 1131, in <module> 
    rcParams = rc_params() 
    File "/usr/local/lib/python3.5/site-packages/matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg/matplotlib/__init__.py", line 975, in rc_params 
    return rc_params_from_file(fname, fail_on_error) 
    File "/usr/local/lib/python3.5/site-packages/matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg/matplotlib/__init__.py", line 1100, in rc_params_from_file 
    config_from_file = _rc_params_in_file(fname, fail_on_error) 
    File "/usr/local/lib/python3.5/site-packages/matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg/matplotlib/__init__.py", line 1018, in _rc_params_in_file 
    with _open_file_or_url(fname) as fd: 
    File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 59, in __enter__ 
    return next(self.gen) 
    File "/usr/local/lib/python3.5/site-packages/matplotlib-1.5.1-py3.5-macosx-10.11-x86_64.egg/matplotlib/__init__.py", line 1000, in _open_file_or_url 
    encoding = locale.getdefaultlocale()[1] 
    File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/locale.py", line 559, in getdefaultlocale 
    return _parse_localename(localename) 
    File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/locale.py", line 487, in _parse_localename 
    raise ValueError('unknown locale: %s' % localename) 
ValueError: unknown locale: UTF-8 

我试着通过pip和pip3进行安装,但它也不起作用。

+0

不用手工安装,它可能更容易使用科学发行版之一,如[安纳康达](https://www.continuum.io/downloads)。这也是[matplotlib文档](http://matplotlib.org/users/installing.html)推荐的。 – DreyFax

+0

我试过这个,但它仍然不起作用。我得到'ImportError:没有名为'matplotlib'的模块 – vhflat

+0

你是否使用Anaconda中包含的python解释器二进制文件?它位于Anaconda根目录中。 – DreyFax

回答

1

问题可能是由不正确的默认LC_CTYPE引起:

$ locale 
LANG="en_GB.UTF-8" 
LC_COLLATE="en_GB.UTF-8" 
LC_CTYPE="UTF-8" # ! 
LC_MESSAGES="en_GB.UTF-8" 
LC_MONETARY="en_GB.UTF-8" 
LC_NUMERIC="en_GB.UTF-8" 
LC_TIME="en_GB.UTF-8" 
LC_ALL= 

作为一种变通方法设置LC_ALL到一个合适的语言环境下运行的Python之前:

$ export LC_ALL=en_GB.UTF-8 
$ python -c "import matplotlib" 
+0

在python3中导入matplotlib时仍会出错,并在python中导入时冻结。 – vhflat

+0

在'export'后面你看到相同的'ValueError:...'吗? –

0

这里更简单的方法做它:

  1. 以管理员身份打开cmd。
  2. 转到您的Python脚本文件夹(通常C:\Python27\Scripts
  3. pip install matplotlib
  4. 点子必须自动为您做到这一点。

希望这会有所帮助! (正如你刚才提到的你曾经尝试过点子,请告诉确切的错误,即使这不起作用。这对我有用)。