0

I am running on Mac 10.14.6 and all the solutions I've tried so far have not worked. I am following the docs for OpenAI spinningup and am stuck on this line:

python -m spinup.run plot data/installtest/installtest_s0

While trying to import matplotlib and plot some graphs however I keep getting:

File /anaconda3/envs/spinningup2/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", line 14, in from matplotlib.backends import _macosx ImportError: 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.

Upon some searching online I see that this is quite a common problem so here is what I have tried so far:


1. https://github.com/scikit-optimize/scikit-optimize/issues/637

Added

import matplotlib
matplotlib.use('PS')

before importing matplotlib.pyplot

I still have the same error.


2. https://markhneedham.com/blog/2018/05/04/python-runtime-error-osx-matplotlib-not-installed-as-framework-mac/

Instead of from matplotlib import pyplot as plt I used:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

However I still get the same error.


3. matplotlib: RuntimeError: Python is not installed as a framework

Add a line:

backend: TkAgg

in file:

~/.matplotlib/matplotlibrc

This does not solve my issue and I have the same error


4.

I try to create a file at ~/.matplotlib/matplotlibrc and populating it with the following text:

$ cat ~/.matplotlib/matplotlibrc
backend: TkAgg

When using the cat command, this somehow crashes my MAC and causes a restart. I am very confused.


Any help or suggestions would be greatly appreciated. I've tried all suggestions I have found on this site with no luck.

rrz0
  • 2,182
  • 5
  • 30
  • 65
  • 1
    are you running the script in Terminal? If so, use `pythonw` instead of `python` – meTchaikovsky Sep 27 '19 at 08:25
  • I am following official docs with no mention of using `pythonw`. You suggest changing the command `python -m spinup.run plot data/installtest/installtest_s0` ? I see what is written in the error message but unsure on how to replace the use of `python` without new error messages cropping up. – rrz0 Sep 27 '19 at 08:27
  • I suggest using `pythonw`, I don't know what your script does, but I got the same error when I ran a script that uses `matplotlib` in Terminal. The problem was fixed when I use `pythonw` instead. – meTchaikovsky Sep 27 '19 at 08:31
  • 1
    Tk right now has some sort of horrible bug on mac os. Try QT5: `matplotlib.use('Qt5Agg')` – Jody Klymak Sep 27 '19 at 21:18
  • Also, the handling of the macOS backend will be updated in more recent matplotlibs so that you no longer need to use `pythonw`, but I forget if that version of matplotlib is released or about to be released. Regardless, please let us know what version of matplotlib you are trying to use. – Jody Klymak Sep 27 '19 at 21:19

1 Answers1

1

I was able to resolve the issue by uninstalling matplotlib, then reinstalling the exact version I needed (happens to be 3.0.3) using Conda.

I also note that Conda installed six (six-1.15.0-py37hecd8cb5_0) as part of this, so not sure what the culprit was but it is fixed now.

Rich
  • 64
  • 4