2019년 1월 22일 화요일

Python : virtualenv에서 matplotlib backend 에러시 해결방법


0. 에러 로그

0.1 예제(bouble.py)
import matplotlib.pyplot as plt
import numpy as np

# create data
x = np.random.rand(40)
y = np.random.rand(40)
z = np.random.rand(40)

print x
# use the scatter function
plt.scatter(x, y, s=z*1000, alpha=0.5)
plt.show()
plt.savefig('foo.png')

0.2 에러
Traceback (most recent call last):
  File "bouble.py", line 4, in <module>
    import matplotlib.pyplot as plt
  File "~/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "~/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "~/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 17, 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 using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

1. 해결방법

스크립트에 backend 구문 추가
import matplotlib
matplotlib.use('TkAgg')

2. ref
- https://matplotlib.org/faq/usage_faq.html#what-is-a-backend

댓글 없음:

댓글 쓰기

추천 게시물

python: SVD(Singular Value Decomposition)로 간단한 추천시스템 만들기( feat. surprise )

svd_example In [15]: # !pip install surprise In [21]: from...