0

I've downloaded and run ez_setup.py from here. Then I ran easy_install -m matplotlib which gave the following wall of text, which I don't understand.

➜  ~ 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

If i now try to import matplotlib I get

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

so then I try using the pkg_resources as suggested by the output above, and get

➜  ~ 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

I've tried installing through pip and pip3 and it doesn't work either.

vhflat
  • 561
  • 6
  • 19
  • Instead of installing it by hand it might be easier to use one of the scientific distributions like [Anaconda](https://www.continuum.io/downloads). This is also recommended by [matplotlib documentation](http://matplotlib.org/users/installing.html). – DreyFax Feb 29 '16 at 10:47
  • I tried this, but it still doesn't work. I get `ImportError: No module named 'matplotlib'` – vhflat Feb 29 '16 at 12:11
  • Did you use the python interpreter binary included in Anaconda? It is in Anaconda root directory. – DreyFax Feb 29 '16 at 12:13

2 Answers2

1

The issue might be caused by an improper default for 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=

As a workaround set LC_ALL to a proper locale prior to running Python:

$ export LC_ALL=en_GB.UTF-8
$ python -c "import matplotlib"
Sergei Lebedev
  • 2,659
  • 20
  • 23
0

Here an easier way to do it:

  1. open cmd as administrator.
  2. Goto your python scripts folder (usually C:\Python27\Scripts)
  3. type pip install matplotlib
  4. pip must do it automatically for you.

Hope this helps! (as you mentioned you had tried pip, please tell the exact error, even if this does not work. This worked for me.)

cchapman
  • 3,269
  • 10
  • 50
  • 68
Ganesh Kathiresan
  • 2,068
  • 2
  • 22
  • 33