Using Python on Mac

5

2

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.

choise

Posted 2010-12-24T22:58:13.937

Reputation: 197

Answers

3

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.

Daniel Beck

Posted 2010-12-24T22:58:13.937

Reputation: 98 421

3

You don't really want to change th default, as the syntax is different enough that apps that require python 2.x will break under 3.

I think that if you type python3 instead of python then it will uses version 3 ( or maybe I just set mine up like that!)

Rich Bradshaw

Posted 2010-12-24T22:58:13.937

Reputation: 6 324

3

Using IDLE is just fine for learning Python. You can either save files with your code or run individual lines of code from the shell.

If you want, you can use text editors such as TextMate or an IDE such as Eclipse with your Mac install of Python 3.1. You just need to point those applications to the location of the Python interpreter.

I did the following post on setting up TextMate with Python 3 in this way. Hope it helps.

Farrell

Posted 2010-12-24T22:58:13.937

Reputation: 31