Jun's Blog

Output, activities, memo and etc.

Set up Python development environment

Note about how to set up python development environment on Mac.

Installed applications are as followings.

  • pyenv: Python managing application such as perlbrew(perl), rbenv(ruby), svm(node.js)
  • Python
  • pip: Python package manager such as Carton(perl), Gem(ruby), npm(node.js)
  • virtualenv: Application to change python for each local directory.

Install pyenv

Use this utility to install pyenv.
yyuu/pyenv-installer · GitHub

$ curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

Add following content to .bash_profile.

$ vi ~/.bash_profile

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Install Python from pyenv

Check available versions of python.
And install latest version of python version2 as default python, because version3 is still not working for several programs.

$ pyenv install -l

$ pyenv install 2.7.10


Add following lines to .bashrc to start python from pyenv.

$ vi ~/.bashrc

if which pyenv > /dev/null; then
    pyenv shell 2.7.10
    pyenv global 2.7.10
    echo "Now using Python 2.7.10 by pyenv"
fi

$ . ~/.bashrc

$ which python
${HOME}/.pyenv/shims/python

$ python --version
Python 2.7.10

pip is included on this python.

Install virtualenv

$ pip install virtualenv

$ which virtualenv
/Users/jun.aruga/.pyenv/shims/virtualenv

That's it.