Encountered such a problem when using matplotlib to plot in a virtualenv environment:
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
…
in <module>
from matplotlib.backends import _macosx
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 Working with Matplotlib in a virtual enviroment see ‘Working with Matplotlib in Virtual environments’ in the Matplotlib FAQ
It seems that it is caused by the different installation and configuration of the virtual environment and the default environment.
After searching for the error message, I found a solution on STO:
1. After pip installs matplotlib, it will generate a .matplotlib directory in the root directory:
➜ bin ll ~/.matplotlib
total 280
-rw-r–r– 1 me staff 78K 10 4 2015 fontList.cache
-rw-r–r– 1 me staff 59K 1 17 15:56 fontList.py3k.cache
drwxr-xr-x 2 me staff 68B 10 4 2015 tex.cache
2. Create a file named matplotlibrc in this directory, the content is:
backend: TkAgg
Then save and exit, restart the Python interactive interface or re-run the script, import is executed normally.
Similar Posts:
- [Solved] Runtime Warning: Font Glyph 20108 is missing. Font.set Fu text (s,0.0,flags=flags), RuntimeWarningGlyph20108missingfromcurrentfontfontsettexts00flagsflags
- Solve the problem of attributeerror: module ‘Matplotlib’ has no attribute ‘verb
- ImportError: cannot import name cbook
- [Solved] UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the fi…
- Python3 ImportError: No module named _ssl [How to Solve]
- Matplotlib.pyplot Plug-in Chinses Font Error: RuntimeWarning: Glyph 26376 missing from current font
- Ubuntu Ubuntu 14.04.5 vmware-tool Installation
- ModuleNotFoundError: No module named ‘PyQt4’ [Spyder Import matplotlib Error]
- [Solved] IOException during persisting of HostData OPatchAuto failed