RuntimeError: Python is not installed as a framework 錯誤解決方案


在virtualenv環境下使用matplotlib繪圖時遇到了這樣的問題:

>>> 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

 

似乎是因為虛擬環境與默認環境的安裝配置不同造成的。

搜索錯誤信息之后,在STO上找到了解決方案:

 

1、pip安裝matplotlib之后,會在根目錄下產生一個.matplotlib的目錄:

➜ 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、在這個目錄下創建一個名為matplotlibrc的文件,內容是:

backend: TkAgg

然后保存退出,重啟Python交互界面或重新運行腳本,import正常執行。

 

STO答案地址:http://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM