Mac上python環境配置

Life is short, I use python

pyenv用來管理多個版本的python在用戶目錄的安裝和使用, 類似rbenv

pyenv與pyenv-virtualenvwrapper:

brew install python pyenv pyenv-virtualenvwrapper    sudo pip install virtualenvwrapper    #如果pip不存在  sudo easy_install pip    >然後你需要把以下內容粘貼到~/.bash_profile文件中  # pyenv  PYENV_ROOT="$HOME/.pyenv"  PATH="$PYENV_ROOT/bin:$PATH"  eval "$(pyenv init -)"    #pyenv virtualenvwrapper  pyenv virtualenvwrapper_lazy

安裝python

//因為MAC El Capitan安裝python3.5.0時找不到zlib,所以加上CFLAGS和LDFLAGS  CFLAGS="-I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include"   LDFLAGS="-L$(brew --prefix openssl)/lib"   pyenv install 3.5.0    pyenv rehash

設置使用python版本

//這裡不推薦使用系統默認版本(即system), 默認版本在用virtualenvwrapper會報錯  pyenv global 3.5.0

pyenv與homebrew衝突解決

#添加到上述文件中  #pyenv not playing nice with homebrew  alias brew="env PATH=${PATH//$(pyenv root)/shims:/} brew"

pyenv基本用法

1.安裝python

pyenv install 2.7.10  pyenv rehash

2.刪除python

pyenv uninstall 2.7.10

3.查看已安裝版本

pyenv versions

4.查看當前使用版本

pyenv version

virtualenvwrapper基本用法

之前記得重新啟動下Terminal, 使上面配置生效

1.創建一個(虛擬?)開發環境

mkvirtualenv testing    workon testing

2.裝一些聽都沒聽過的依賴包(前面的括弧裡面會顯示你現在用哪一個環境的)

pip install ... (例如: cherrypy, routes)

3.用的不爽刪了就是了

deactivate (或者切換到其他python虛擬環境中)    rmvirtualenv testing