在Mac下初始化python開發環境

來源:互聯網
上載者:User

安裝Xcode, Command line tools

作為開發人員,肯定需要gcc,clang這些環境,Xcode介面也能下載Command line tools,但是下載好幾次都有簽名錯誤的問題,直接去官網下載

使用瀏覽器下載一段時間鎖屏會停止下載,又不能續傳。所以我還是習慣命令列下載.可以在這裡找到https://github.com/orzrd/mytools/blob/master/adc_download.sh 比如下載xcode:

./adc_download.sh http://adcdownload.apple.com/Developer_Tools/xcode_4.6.3/xcode4630916281a.dmg

安裝git

在這裡 http://git-scm.com/download/mac,但是你需要注意版本和你的os的版本的對應關係

安裝brew-包管理工具

以後我通過brew安裝的軟體都放在這個目錄

sudo chown -R `whoami` /usr/local
git init
git remote add origin git://github.com/mxcl/homebrew.git
git pull origin master

安裝一些常用工具


brew install wget the_silver_searcher tree tmux htop mysql autojump mongodb zsh-completions
sudo easy_install pip
sudo pip install virtualenv
sudo pip install virtualenvwrapper
# 設定mysql和mongodb開機自啟動
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
iln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

安裝配置oh-my-zsh和dotfiles


git clone https://github.com/robbyrussell/oh-my-zsh.git .oh-my-zsh
chsh -s /bin/zsh
git clone https://github.com/dongweiming/dotfiles.git ~/dotfiles
cd dotfiles
./install.sh vim

配置一個虛擬python環境

export WORKON_HOME=~/envs
mkdir $WORKON_HOME -p
source /usr/local/bin/virtualenvwrapper.sh
mkvirtualenv --no-site-packages XXX # 這裡建立了一個叫做XXX的環境,並且不會依賴site-package,需要你在環境中自訂下載
pip install -r requirements.txt #根據檔案安裝依賴

zshrc的配置可以看我的dotfiles,我粘貼出來

export ANTIGEN_DEFAULT_REPO_URL=https://github.com/dongweiming/oh-my-zsh      
source ~/dotfiles/antigen/antigen.zsh                                         
                                                                              
antigen use oh-my-zsh                                                         
                                                                              
if [ "${OSTYPE:0:6}"="darwin" ]; then                                         
  antigen-bundle osx                                                          
  antigen-bundle brew                                                         
  export PATH=$(brew --prefix ruby)/bin:$PATH:/usr/local/sbin:~/bin
else                                                                          
  export PATH=$PATH:~/bin                                                     
fi                                                                            
antigen bundles <<EOB                                                         
  git-extras                                                                  
  pip                                                                         
  python                                                                      
  autojump
  django                                                                      
  ruby                                                                        
  git-flow                                                                    
  virtualenvwrapper                                                           
  git                                                                         
  github                                                                      
  supervisor                                                                  
  tmux                                                                        
  vagrant                                                                     
  history                                                                     
  zsh-users/zsh-syntax-highlighting                                           
  zsh-users/zaw                                                               
  zsh-users/zsh-history-substring-search                                      
  ~/.oh-my-zsh --no-local-clone                                               
EOB                                                                           
                                                                              
antigen theme sheerun/oh-my-zsh-powerline-theme powerline                    
                                                                              
antigen apply                                                                 
                                                                              
autoload -U zmv                                                               
export SSH_ASKPASS=""                                                         
alias rake='noglob rake'                                                      
export WORKON_HOME=~/envs                                                     
source `which virtualenvwrapper.sh`                                           
alias social='workon social;cd ~/social_master'
alias ls='ls -hF --color=auto'
source ~/.oh-my-zsh/custom/powerline.zsh
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"

for keycode in '[' 'O'; do
  bindkey "^[${keycode}A" history-substring-search-up
  bindkey "^[${keycode}B" history-substring-search-down
done
unset keycode


# bind k and j for VI mode
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down

安裝coreutils

Mac說白了就是freeBSD+一些外掛程式的組合,所以常用工具例如ls 、grep也都是freeBSD版本,比如我使用rm刪除檔案,就必須rm -rf xx 而不能 rm xx -rf s實在腦殘

brew install coreutils

添加PATH到.zshrc

PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"                          
MANPATH="$(brew --prefix coreutils)/libexec/gnuman:$MANPATH"

修改ls配色

git clone git@github.com:seebi/dircolors-solarized.git
# dircolors就在上面的coreutils中
echo 'eval `dircolors ~/lib/dircolors-solarized/dircolors.256dark`' >> ~/.zshrc

安裝octopress-為我的部落格 僅供參考

# 預設的ruby是1.8.7的,我想要2.0的
brew install ruby
gem install bundler
bundle install
bundle update rake #安裝的版本和octoress要求的9.2.2要高,所以需要升級
git clone https://github.com/imathis/octopress.git oc
cd oc
# 為啥會有下面的一堆cp?其實是為了升級我的octopress
cp ../octopress/Rakefile .
cp ../octopress/_config.yml .
cp -rp ../octopress/source .
# 以下是我自己寫的幾個指令碼
cp ../octopress/plugins/pygments_code.rb plugins
cp ../octopress/plugins/shjs.rb plugins
cp ../octopress/plugins/tag_cloud.rb plugins
cp ../octopress/sass . -rp
# 然後你就可以產生了
rake generate

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.