在 Mac 中用 homebrew 裝的 Python3 中安裝 graph-tool

目前 Homebrew 提供的 Python 3 是 3.4.1,所以以下各路徑和檔案修改都是用 3.4.1,若版本有變要做相對應的修改

  1. brew install python3
  2. pip3 install numpy
  3. brew install gcc (scipy 需要 Fortran Compiler)
  4. pip3 install scipy
  5. 修改 /usr/local/Library/Formula/boost.rb https://gist.github.com/jiayun/f331db2bef429d532ea4
  6. brew install boost –with-python3 –c++11
  7. 安裝 XQuartz http://xquartz.macosforge.org/
  8. brew install pkg-config
  9. brew install –c++11 cgal cairo cairomm py3cairo google-sparsehash
  10. pip3 install matplotlib
  11. brew tap homebrew/science
  12. 修改 /usr/local/Library/Formula/graph-tool.rb https://gist.github.com/jiayun/66682b5deb80bb32d0a3
  13. cd /usr/local/Cellar/py3cairo/1.10.0/include/pycairo/
  14. ln -s py3cairo.h pycairo.h
  15. export PYTHON=/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/bin/python3.4m
  16. brew install graph-tool –with-google-sparsehash

不要用 CherryPy

網路上一些資料 CherryPy 效能都不太好,像這篇

http://mindref.blogspot.tw/2012/09/python-fastest-web-framework.html

它連結的其他評比也都不出色

實際用起來還真的很有問題,我們是用來做 REST API,但是 API 設定多了之後,效能就嚴重下降(每分鐘七千多個 request)

同樣數量的 API 用 Flask + Flask-RESTful 寫,效能完全大勝(每分鐘三萬五千多個 request)

評 Programming in Python 3: A Complete Introduction to the Python Language (2nd Edition)

Programming in Python 3: A Complete Introduction to the Python Language (2nd Edition)

這本一些基本觀念講得還滿詳細清楚的

不過程式碼不是很好,像開檔案沒有用 with 也沒有 close,不是好習慣

講自訂 class 的部分有一個地方明明要做 immutable 但 &= 實作改了 private value,但 __eq__ 根據那個 private value,__hash__ 卻是根據 id(),完全是有問題的寫法,果然一個小測試就會錯了:

>>> from FuzzyBool import FuzzyBool
>>> g = FuzzyBool(.5)
>>> g
FuzzyBool(0.5)
>>> id(g)
4306629328
>>> x = { g: 1 }
>>> x
{FuzzyBool(0.5): 1}
>>> g&=FuzzyBool(.1)
>>> g
FuzzyBool(0.1)
>>> id(g)
4306629328
>>> x[g]
1
>>> h = FuzzyBool(.1)
>>> h
FuzzyBool(0.1)
>>> id(h)
4301064016
>>> x[h]
Traceback (most recent call last):

如過 FuzzyBool 的地方換成 Python 的 int,最後那行是完全不會有問題的

所以這種很硬底子的地方講得又不夠清楚

不過還算值得一讀就是了,重要的東西和 library 都有介紹到

評 Head First Python

快速翻完,覺得這本不是很優,沒有非常適合給入門用

Python 基礎講得很少,然後後半本開始扯到 web, app

我覺得很容教壞新手,因為它提的那些做法都不是真正 production 等級的做法

所以後半本是浪費時間,前半本則是二百多頁內容,其實根本一篇文章就可以講完,也是浪費時間….