10

I'm having a lot of difficulty installing matplotlib in my pipenv, I believe due to the non-python dependencies.

The error I am getting is

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.

This is on MacOS X (High Sierra). I have installed libpng freetype and pkg-config via brew, but this does not seem to resolve the issue.

My hope for this pipenv is for it to be deployed to Heroku, if that makes any difference.

Brian Hamill
  • 2,466
  • 4
  • 12
  • 20
  • Are you running this inside the virtualenv? Do you also have pyenv installed? – Aristu Mar 19 '18 at 15:45
  • Did you go through the recommended steps at [osx_framework](https://matplotlib.org/faq/osx_framework.html)? – ImportanceOfBeingErnest Mar 19 '18 at 15:46
  • 1
    I have pyenv installed. I have attempted to follow those steps @ImportanceOfBeingErnest however admittedly I find them very difficult to understand and I'm not sure which ones to implement. Any advice would be much appreciated – Brian Hamill Mar 19 '18 at 16:59
  • Yep, that comment was meant for you to update the question on where exactly the problem is with those steps. (I'm not using mac so I personally can't help you, but I can help you write a question that might be easier to grasp for others) – ImportanceOfBeingErnest Mar 19 '18 at 17:12

2 Answers2

11

I resolved this error by following the instructions in this answer while also using this document to find where the matplotlibrc file is located.

To do this inside my pipenv I ran the following code:

python
>>> import matplotlib
>>> matplotlib.matplotlib_fname()

Using the output I navigated to the matplotlibrc file within my virtual environment and added backend: TkAgg to the file.

This resolved my issue. Hopefully this question can be of help to others!

Brian Hamill
  • 2,466
  • 4
  • 12
  • 20
7

Before trying as @brian suggested, for me, it worked by just adding matplotlib.use('TkAgg') after import matplotlib and before from matplotlib import pyplot

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

Environment

  • This is on MacOS X (High Sierra)
  • Python 3.7 version
  • pipenv, version 2018.7.1
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Jayasagar
  • 2,046
  • 19
  • 22