RuntimeError: Python is not installed as a framework when using matplotlib

The author reported an error when running after the first installation of matplotlib.

1 import matplotlib as mlb
2 from matplotlib import pylab as pl
3 
4 
5 x = [1,3,5,7,6,9,10,13,16]
6 y = [3,4,5,7,9,0,1,2,3]
7 
8 pl.plot(x,y)
9 pl.show()

Error content

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.

 

Solution:

1. Open a terminal and enter cd ~/.matplotlib

2. New file, vi matplotlibrc

3. Add content to the file, press the i key, then enter the content backend: TkAgg , then click esc, enter: number, enter wq, and then press Enter to confirm

4. Rerun the script

The result is as follows:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324711479&siteId=291194637