Pipenv安装matplotlib

Bri*_*ill 9 python macos matplotlib pipenv

我在我的pipenv中安装matplotlib有很多困难,我相信由于非python依赖项.

我得到的错误是

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.

这是在MacOS X(High Sierra)上.我已经安装libpng freetypepkg-config通过brew,但这似乎没有解决问题.

我对这个pipenv的希望是它被部署到Heroku,如果这有任何区别的话.

Bri*_*ill 11

我按照本答案中的说明解决了此错误,同时还使用此文档查找matplotlibrc文件所在的位置.

为了在我的pipenv中执行此操作,我运行了以下代码:

python
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
Run Code Online (Sandbox Code Playgroud)

使用输出我导航到我的虚拟环境中的matplotlibrc文件并添加backend: TkAgg到文件中.

这解决了我的问题.希望这个问题可以帮助别人!


Jay*_*gar 6

在尝试@brian建议之前,对我来说,它的工作原理是在matplotlib.use('TkAgg')之后import matplotlib和之前添加from matplotlib import pyplot

import matplotlib matplotlib.use('TkAgg') from matplotlib import pyplot

环境

  • 这是在MacOS X(High Sierra)上
  • Python 3.7版本
  • pipenv,版本2018.7.1