在安裝numpy和matplotlib過程中,直接提示“numpy requires System Python 2.7 to install”,但是mac電腦自帶的Python本身是2.7,在stackoverflow上找到一篇文章
http://stackoverflow.com/questions/20058733/numpy-requires-system-python-2-7-to-install
和我遇到的問題是一樣的。意思是numpy和matplotlib模塊需要32位的Python,但是mac自帶的是64位的,需要我們重新下載32位Python進行安裝。
32位安裝地址:https://www.python.org/download/releases/2.7.6/
我重新下載並安裝后,重啟電腦,numpy和matplotlib安裝成功。
mac安裝matplotlib的步驟:
http://www.tuicool.com/articles/2Mj6Jb
首先安裝numpy,去 sourceforge 下載了numpy-1.7.1-py2.7-python.org-macosx10.6.dmg,安裝是傻瓜式的,安裝完在python命令行輸入import numpy測試沒有問題。
然后安裝matplotlib,去 github 下載了matplotlib-1.2.1-py2.7-python.org-macosx10.6.dmg,也是傻瓜式安裝,安裝完在python命令行輸入import matplotlib,提示not load X11的一個東西,去下載 XQuartz 並安裝,再次輸入import matplotlib就沒有問題了。
然后寫了下面這段簡單的代碼測試:
- import matplotlib.pyplot as plt
- plt.plot([1,2,3])
- plt.ylabel('some numbers')
- plt.show()
然后問題來了,報錯: STACK: Stack after current is in use 。折騰了一整天,把官方的faq全看了,看到 這篇 講到在普通python命令行下使用matplotlib的限制,試了下也不行。回想以前的經驗,在pydev設置里配置環境變量什么的也無效。最后無意間在matplotlib的github頁面看到這一句話:
matplotlib-1.2.0-py2.7-python.org-macosx10.6.dmg — Binary installer for python.org's 64-bit python 2.7 and MacOS X 10.6 or later
會不會是32位和64位python的問題,因為前幾日為了使用MySQLdb安裝了python2.7的32位版本,而當前系統默認使用這個版本。於是刪除了之前安裝的64位版本並下載和安裝了這個版本的matplotlib:
matplotlib-1.2.0-py2.7-python.org-macosx10.3.dmg — Binary installer for python.org's 32-bit python 2.7 and MacOS X 10.3.9 or later
再測試那段代碼,就看到圖表了:
這個問題浪費了一天的時間,唯一查到的 stackoverflow 答案也沒有人能解答。但是令人奇怪的是安裝的64位numpy又完全沒有問題= =。