Sunday, February 15, 2015

Python Development Setup for OS X users

There are lots of options for python developers. Whether use Python 2 or Python 3 which IDE, how to do  package management so on. This guide is for beginners who are confused with many options.

Which Python version to use

It is more safe to use Python 2.7 not all packages are supported with Python 3. For example if you want to develop web application with Django only 590 packages out of 2656 are supported for Python 3. You can look at https://www.djangopackages.com/ which packages are supported. So I recommend  to learn first Python 2.7. Top most popular packages 289 out of 360 are supported while I am writing this blog  https://python3wos.appspot.com/ . Python 3 is a better language, if all your needed packages for your project are supported then use Python 3. It is possible to coexist Python 2.7 and Python 3 in the same system.

Python version and enviroment management with Pyenv


I am using OS X Yosemite 10.10.2 and default python version comes with it is 2.7.6 which is  not the latest one. My recommended way to install any version of python is via pyenv.  First install pyenv with Homebrew package manager. If you do not have this general purpose package manager (brew) install it first. Then:

brew install pyenv
brew install pyenv-virtualenv
brew install ccache
brew install pyenv-ccache

Put this code to your .profile file

if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)";fi

Now we are ready to go install python. First list python versions available:

pyenv install -l
Available versions:
2.7.8
  2.7.9
  3.0.1
  3.1-dev
....
  3.3.4
  3.3.5
  3.3.6
  3.4.0
  3.4-dev
  3.4.1
  3.4.2
  3.5-dev

Now install python 2.7.9

pyenv install 2.7.9

if you get following error:
ERROR: The Python zlib extension was not compiled. Missing the zlib?
then append the command with following for workaround:


CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 2.7.9


Now we can activate python 2.7.9 globally as follow:

python global 2.7.9



Now let's install also python 3.4.2
pyenv install 3.4.2


No comments:

Post a Comment