Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipenv install matplotlib

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.

like image 958
Brian Hamill Avatar asked Mar 19 '18 15:03

Brian Hamill


People also ask

Does Python 3.10 support matplotlib?

Matplotlib 2.0. x supports Python versions 2.7 through 3.10.

How do I know if matplotlib is installed?

To verify that Matplotlib is installed, try to invoke Matplotlib's version at the Python REPL. Use the commands below that include calling the . __version__ an attribute common to most Python packages.

How do I download matplotlib in Vscode?

Install matplotlib by entering its name into the search field and then selecting the Run command: pip install matplotlib option. Running the command will install matplotlib , and any packages it depends on (in this case that includes numpy ). Choose the Packages tab. Consent to elevation if prompted to do so.


2 Answers

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
like image 106
Jayasagar Avatar answered Sep 18 '22 19:09

Jayasagar


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!

like image 22
Brian Hamill Avatar answered Sep 20 '22 19:09

Brian Hamill