Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run matplotlib in Pycharm on macOS?

I can run code through terminal and have a matplotlib window pop up with the graph but not through Pycharm. All I get is an error saying:

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.

I'm not sure how to install Python as a framework or what that really means. I've googled about but I don't want to mess my system up.

Can someone offer a solution at least of what I should be trying to do or what to google around for.

Sorry if I lack some of the technical language/knowledge to explain this problem. Thanks

  • macOS High Sierra 10.13.1
like image 271
WeAreSystems Avatar asked Dec 15 '17 14:12

WeAreSystems


People also ask

Can we use matplotlib in PyCharm?

Professional feature: download PyCharm Professional to try. In this tutorial, you operate in Scientific Mode and use Matplotlib and NumPy packages to run and debug a Python code with data visualization. Before you start, ensure the following is installed: Conda interpreter.

How do I know if matplotlib is installed Mac?

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.

Can PyCharm show plots?

Interactive plots in the SciView window are not supported by PyCharm at the moment. If you want to use the mouse cursor to see the values at specific graph points, you can render plots in the native matplotlib GUI.


2 Answers

If you install matplotlib with pip, or conda, you should have a directory ~/.matplotlib.

Inside that directory create, or open if it already exists, a file called matplotlibrc.

To make TkAgg the default backend just add the line backend: TkAgg

like image 130
Batman Avatar answered Oct 19 '22 07:10

Batman


I found a short term fix until I can make changes to the necessary files from user Iron Pillow.

import matplotlib matplotlib.use('TkAgg')

I just insert this before I import any matplotlib subpackages.

like image 4
WeAreSystems Avatar answered Oct 19 '22 09:10

WeAreSystems