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 -)"; fiif 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:
Now install python 2.7.9
pyenv install 2.7.9
if you get following error:
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
pyenv install -lAvailable versions:2.7.82.7.93.0.13.1-dev....3.3.43.3.53.3.63.4.03.4-dev3.4.13.4.23.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