10
10

More than 5 years have passed since last update.

Setup modern Python environment with Homebrew

Last updated at Posted at 2012-09-28

Based on http://ymotongpoo.hatenablog.com/entry/20120516/1337123564
Unfortunately, pythonbrew is owkn...
Let's use virtualenv for switching multiple Python versions!

Install Python and related tools

I mainly use Python3 :)
Latest Python3 version in Homebrew is Python 3.2.3.

% brew install python3
% /usr/local/share/python3/easy_install3 pip
% /usr/local/share/python3/easy_install3 virtualenv
% /usr/local/share/python3/easy_install3 virtualenvwrapper

Configuration in .zshrc

PYTHON_VER=3.2
export HOMEBREW_PREFIX=/usr/local
export VIRTUALENVWRAPPER_PYTHON=$HOMEBREW_PREFIX/bin/python$PYTHON_VER
export VIRTUALENV_BIN=$HOMEBREW_PREFIX/share/python3
export WORKON_HOME=$HOME/.virtualenvs
. $VIRTUALENV_BIN/virtualenvwrapper.sh
export PATH=$VIRTUALENV_BIN:$PATH

mkvenv ()
{
    base_python=`which python$1` 
    mkvirtualenv --distribute --python=$base_python $2
}

Try!

% source .zshrc
% mkvenv 3.2 dev
(dev)% which python
$WORKON_HOME/dev/bin/python
(dev)% python -V                                   
Python 3.2.3
(dev)% pip install tornado
(dev)% deactivate
% source $WORKON_HOME/dev/bin/activate
(dev)% 
10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10