0

I wanted to install Matplotlib in Mac (10.7.5 Lion) where python (2.7.1), pip (8.1.2), numpy (1.11.0), astropy(1.2) are already installed and are working as expected. First I tried with the command

sudo pip install matpltlib

and it showed that Matplotlib 1.5.1 has been installed successfully. But when I entered python and typed import matplotlib it showed an error message like this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/matplotlib/__init__.py", line 1131, in <module>
    rcParams = rc_params()
  File "/Library/Python/2.7/site-packages/matplotlib/__init__.py", line 975, in rc_params
    return rc_params_from_file(fname, fail_on_error)
  File "/Library/Python/2.7/site-packages/matplotlib/__init__.py", line 1100, in rc_params_from_file
    config_from_file = _rc_params_in_file(fname, fail_on_error)
  File "/Library/Python/2.7/site-packages/matplotlib/__init__.py", line 1018, in _rc_params_in_file
    with _open_file_or_url(fname) as fd:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/Library/Python/2.7/site-packages/matplotlib/__init__.py", line 1000, in _open_file_or_url
    encoding = locale.getdefaultlocale()[1]
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 496, in getdefaultlocale
    return _parse_localename(localename)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

I do not understand what exactly the problem is. I have opened all those .py files and have read the commands in lines specified. Since these are read-only files (even from root) nothing can be edited. I do not know how to resolve this.

Well, I then uninstalled it by pip, and tried to install from source.When I try to build it through python setup.py build (after downloading 280 MB source file) it ends up will several errors like this-

src/_macosx.m:2494: warning: implicit conversion shortens 64-bit value into a 32-bit value 
src/_macosx.m:1337: error: ‘for’ loop initial declaration used outside C99 mode
lipo: can't open input file: /var/folders/ks/31hhg2hj3273tbk2xwbjfv2h0000gn/T//ccEOsZZ4.out (No such file or directory)
lipo: can't open input file: /var/tmp//ccLauouU.out (No such file or directory)
error: command 'llvm-gcc-4.2' failed with exit status 1

I checked, there is no directory called var. I cannot debug this anymore.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Sanskriti
  • 1
  • 1
  • What does the command `locale` (in your terminal, not Python) produce? You seem to have an invalid locale configuration. – Martijn Pieters Jun 09 '16 at 17:49
  • It produces "LANG= LC_COLLATE="C" LC_CTYPE="UTF-8" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" LC_ALL= " – Sanskriti Jun 09 '16 at 19:11
  • Note your `LC_CTYPE` variable; a locale variable should be set to a language code, plus a dot and a characterset. Set it to `LC_CTYPE="en_US.UTF-8"`; you may want to find where it is set. – Martijn Pieters Jun 09 '16 at 20:48

1 Answers1

0

You have misconfigured your locale; matplotlib appears to be correctly installed but it calls the locale.getdefaultlocale() function when imported.

That function tries to determine your current locale from the 'LANGUAGE', 'LC_ALL', 'LC_CTYPE', and 'LANG' environment variables. At least one of those is not set to a language code plus encoding; you have it set to an encoding only.

Use the locale command to see what the current settings are. Any that are currently set to just UTF-8 are incorrectly set and are missing the language code (like en_US or en_GB or es_ES, etc). You should normally leave setting locale variables to your OS X terminal anyway; see https://apple.stackexchange.com/questions/21096/where-does-lang-variable-gets-set-in-mac-os-x

Check your ~/.profile and perhaps ~/.bashrc files to see where the erroneous variable is being set and remove that line, or at the very least add a language code to it, separated by a dot.

Community
  • 1
  • 1
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343