我在安装matplotlib时遇到问题

时间:2016-02-29 10:40:17

标签: python python-3.x matplotlib

我已经从here下载并运行了ez_setup.py。然后我跑easy_install -m 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安装它也不起作用。

2 个答案:

答案 0 :(得分: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=

作为一种解决方法,在运行Python之前将LC_ALL设置为适当的语言环境:

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

答案 1 :(得分:0)

这是一种更简单的方法:

  1. 以管理员身份打开cmd。
  2. 转到你的python脚本文件夹(通常是C:\Python27\Scripts
  3. 输入pip install matplotlib
  4. pip必须自动为你做。
  5. 希望这有帮助! (正如你所提到的,你曾试过pip,请告诉确切的错误,即使这不起作用。这对我有用。)