Matplotlib etc. cannot be imported in VirtualEnv environment

environment

--Python 3.4.3 (in Pyenv)

The latest version is included as of December 11, 2015

error contents

Traceback (most recent call last): File "", line 1, in File "/Users/user/graph/lib/python3.4/site-packages/matplotlib/init.py", line 1131, in rcParams = rc_params() File "/Users/user/graph/lib/python3.4/site-packages/matplotlib/init.py", line 975, in rc_params return rc_params_from_file(fname, fail_on_error) File "/Users/user/graph/lib/python3.4/site-packages/matplotlib/init.py", line 1100, in rc_params_from_file config_from_file = _rc_params_in_file(fname, fail_on_error) File "/Users/user/graph/lib/python3.4/site-packages/matplotlib/init.py", line 1018, in _rc_params_in_file with _open_file_or_url(fname) as fd: File "/Users/user/.pyenv/versions/3.4.3/lib/python3.4/contextlib.py", line 59, in enter return next(self.gen) File "/Users/user/graph/lib/python3.4/site-packages/matplotlib/init.py", line 1000, in _open_file_or_url encoding = locale.getdefaultlocale()[1] File "/Users/user/graph/lib/python3.4/locale.py", line 556, in getdefaultlocale return _parse_localename(localename) File "/Users/user/graph/lib/python3.4/locale.py", line 484, in _parse_localename raise ValueError('unknown locale: %s' % localename) ValueError: unknown locale: UTF-8

In short, locale: UTF-8

locale setting

export

(graph)pc-name:graph user$ export LC_ALL='ja_JP.UTF-8'

Verification

(graph)pc-name:graph user$ locale
LANG=
LC_COLLATE="ja_JP.UTF-8"
LC_CTYPE="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_ALL="ja_JP.UTF-8"     #this guy

Can it be imported again?

>>> import matplotlib.pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/matplotlib/pyplot.py", line 114, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/Users/user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
    from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

I'm still doing something ...

Create ~ / .matplotlib / matplotlibrc

backend : TkAgg

Add

Another solution

Also, as @aion pointed out, it seems that you can also take measures against this error below! Thank you @aion: muscle:

import matplotlib
matplotlib.use('TkAgg')

Recommended Posts

Matplotlib etc. cannot be imported in VirtualEnv environment
Python environment settings (virtualenv + pip cannot be done)
Tensorflow cannot be imported
Video cannot be loaded with Spyder in Python development environment
Django cannot be installed in the development environment of pipenv + pyenv
Jupyter Notebook 6.0.2 cannot be installed in the Python 2.7 environment created in Anaconda
pyenv + pyenv-Automatically load the virtualenv environment in the virtualenv environment
I tried putting virtualenv in Cygwin environment
Modules cannot be imported in Python on EC2 run from AWS Lambda
Tkinter could not be imported in Python
Items that cannot be imported with sklearn
De-VBA Excel tool! Eliminate VBA tool with Python in environment where Python cannot be installed
Work in a virtual environment with Python virtualenv.
PIL cannot be installed by virtualenv with pyenv
Install LightGBM in an OS X virtualenv environment
python in virtualenv
Japanese can be used with Python in Docker environment
[Memorandum] Japanese keys cannot be used in python string.Template.substitute
list comprehension because operator.methodcaller cannot be used in python 2.5
Operators ++,-cannot be used in python (difference from php)
How to pass matplotlib backend settings in environment variables
[Redash] Standard library cannot be used in python function
Excel sheet cannot be specified in sheet_name of pd.read_excel
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.