我是一名 ruby 开发人员,我已经开始为一个项目学习 python。我安装了 pyenv、pyenv virutualenv、ipython、notebook、matplotlib。除了我调用的部分之外,一切都工作正常
import matplotlib.pyplot as plot
然后我从笔记本中收到此错误:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-1-08ad587cbf6a> in <module>()
----> 1 import matplotlib.pyplot as plot
/Users/ilab/.pyenv/versions/2.7.11/envs/mlcoursera/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
112
113 from matplotlib.backends import pylab_setup
--> 114 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
115
116 _IP_REGISTERED = None
/Users/ilab/.pyenv/versions/2.7.11/envs/mlcoursera/lib/python2.7/site-packages/matplotlib/backends/__init__.pyc in pylab_setup()
30 # imports. 0 means only perform absolute imports.
31 backend_mod = __import__(backend_name,
---> 32 globals(),locals(),[backend_name],0)
33
34 # Things we pull in from all backends
/Users/ilab/.pyenv/versions/2.7.11/envs/mlcoursera/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py in <module>()
22
23 import matplotlib
---> 24 from matplotlib.backends import _macosx
25
26
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.
谁能帮我让它发挥作用吗?
ps:我使用的是带有 pyenv 的 python 2.7.1。
最佳答案
Matplotlib 需要在 OS X 上安装框架才能操作 GUI 元素。 您可以使用这样的命令安装框架版本,了解您的 python 版本和环境名称:
env PYTHON_CONFIGURE_OPTS="--enable-framework CC=clang" pyenv virtualenv <python_version> <env_name>
关于python - 无法使用 pyenv ipython 笔记本导入 matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38139387/