简体   繁体   中英

Python via Conda on Mac OS X: RuntimeError: Python is not installed as a framework

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM