Pages

Wednesday, July 27, 2016

Issue when import matplotlib in Virtualenv in Python

Error:
import matplotlib.pyplot as plt

Traceback (most recent call last):

  File "", line 1, in

  File "/Users/jwithanawasam/MachineLearning/Caffe2/venv/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in

    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()

  File "/Users/jwithanawasam/MachineLearning/Caffe2/venv/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup

    globals(),locals(),[backend_name],0)

  File "/Users/jwithanawasam/MachineLearning/Caffe2/venv/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in

    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


If you encounter the above error, there is an easier way to fix that without using Matplotlib FAQ ;)

Soution:

If you have already installed Matplotlib install using the following command.
pip install matplotlib

cd ~/.matplotlib
vi matplotlibrc

Add the following content in opened matplotlibrc file.

backend: TkAgg

Try import matplotlib.pyplot as plt and it should work without errors.

No comments:

Post a Comment