Python on Mac – How to Install and Use Python on macOS

installationmacmacososx-snow-leopardpython

I want to learn Python using my Mac.

Now I want to setup a Python version >= 3.1.3, because my materials for learning are using this version.

Typing python into terminal results version 2.6.1, using the dmg installer on python.org doesn't have an effect on the python version in terminal, but it's bundled with an own shell under Applications/Python 3.1/Idle.app

Should I use this shell for learing or is there a better way, updating the Python version bundled with Snow Leopard?

I already tried defaults write com.apple.versioner.python Version 3.1.3 or defaults write com.apple.versioner.python Version 3.0 without any result.

Best Answer

Python 3 breaks things. That's why it doesn't replace Python 2, and python still launches 2.


To get Python 3, type python3. You might need to change your $PATH by editing ~/.bash_profile and adding:

PATH="/Library/Frameworks/Python.framework/Versions/3.1/bin:${PATH}"
export PATH

You could define a shell function or alias to map python to python3, this way old scripts would continue to run, and you can type python and get version 3.

Add to .bash_profile:

alias python='python3'

/usr/bin/env python continues to provide Python 2.

Related Question