I'm a newbie programmer just installing Python 3.2, but I know I also have an older version of Python on my machine. in fact, I think Macbook comes with it installed. Do I have to worry about having different versions on my computer when I try to start learning Python?
-
4Whoever voted to close 'off-topic'; programming tools are well within the SO boundaries. Is there another SE site more appropriate? – Josh Smeaton Apr 05 '11 at 13:09
-
Related answer: http://stackoverflow.com/questions/1541776/upgrade-python-to-2-6-on-mac/1542144#1542144 – Sridhar Ratnakumar Apr 05 '11 at 16:38
7 Answers
For the most part, you don't have to worry about conflicts with system Python. In fact it is recommended to install a different Python version instead of working with system Python. Also consider using virtualenv
and virtualenvwrapper
to maintain any dependencies for each project easily without conflicts.

- 37,112
- 11
- 62
- 61
It really depends what OS you're talking about. I'm assuming you're talking about a Mac, since you mentioned Macbook.
Macs come with 2.5 and 2.6 installed as far as I'm aware. At least mine has both those versions, and I've only installed 2.7 manually.
You can check which version of python is the current 'system' python by doing the following in terminal:
// check the version of system python
python --version
// tells you where the system version of python is on your PATH
which python
On *nix type Operating Systems, like your Mac, applications aren't really 'installed', like they are in Windows (eliding details). Instead, application files are placed in various different parts of the file system. Python, for example, is placed into the following directory (by default) when installing 2.7:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Since this directory isn't on the system PATH
, this version of python won't be used when simply calling python
from the command line. The system will search all the folders in the PATH
environment variable for an executable file called python. It will usually find it in /usr/bin/
or something similar.
To make a new version of Python the 'system' python, you have a couple of options:
- Modify your .bash_profile, and prepend the path to your new python to the
PATH
environment variable. - symlink the new version of python to a directory already on your PATH like /usr/bin/
Be aware that Mac python installers can modify your .bash_profile
(in your home directory), to force the new version to be the default system version. This is what my bash_profile shows:
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
You can happily run multiple versions of python on the same system. A particular version is usually the default though, and that's whatever executable python file is found on the PATH first.
If you want to use a different version at any particular point in time, you can:
/path/to/python/2.4/python some_script.py
/path/to/python/2.7/python some_script.py
/path/to/python/3.2/python some_script.py
That will execute the script some_script.py
under 3 different versions of python. Of course, you need to make sure that the /path/to/python is correct.
So yes, you need to be mindful about what version of python you are going to be using, hopefully this will guide you into understanding how applications are installed and which version of an application is launched by default when you don't provide a path.

- 47,939
- 24
- 129
- 164
-
thanks a lot. very helpful. If you happen to know a way I can study more about these commands you're entering in the command line, please let me know a book I could read or something. cheers. – Leahcim Apr 05 '11 at 14:33
-
@Michael, as you use the OS more and more for development, you'll learn these things fairly naturally. Reading install guides, googling issues with applications etc will all contribute to your knowledge. I've learnt by doing, and I've only been playing around with *nix systems for just over 6 months – Josh Smeaton Apr 06 '11 at 01:42
Yes, 3.x Python syntax is not backward-compatible with 2.x. So if you learn Python 3.x you might not be able to port your knowledge to Python 2.x.
Moreover you should choose if you want to learn 3.x or 2.x. 2.x is far more widespread than 3.x, but 3.x is where Python is heading. No more innovation will happen in 2.x, and in mid-term most frameworks will be ported to 3.x (right now there are some notable exceptions)
Hope that helps!

- 12,378
- 5
- 40
- 54
In general, you should be fine. Since the Mac is BSD-based, it should maintain the "python" command as pointing to the version that your system requires, which is usually an older version like 2.5. You may have to use a command like python3
to run your Python 3 programs, but other than that it should be transparent to you.
As you learn and become more advanced, you can begin using the virtualenv
system to maintain separate Python installations for multiple projects.

- 9,125
- 1
- 29
- 43
Python version with different major or minor version numbers can be installed in parallel. For example, you can have 2.4, 2.5, 2.6, 2.7 and 3.1 on the same machine. However, you can't have versions with the same major and minor number installed at the same time (at least, not without tricks), so you can't have 2.5.2 and 2.5.4 at the same time.
Note that you will have to install any third-party libraries once for every Python version.

- 4,236
- 2
- 23
- 24
-
thanks a lot. The default version on my Mac is 2.5, but I want to install 2.5.4 . Can you tell me what I should do? Do I have to uninstall the default 2.5? before installing the 2.5.4? – Leahcim Apr 05 '11 at 14:40
It is very well possible to have multiple versions of python on your machine. Just make sure, that if you call python
in your console it uses the python you want it to use. Same goes for your IDE.
Regarding the version: It is always nice to have the latest version on board (in python however there are compatibility issues to take into account) , since there might be features you want to use, that are only available with a certain version and upwards. Since this is sometimes tricky to find out, especially if you are new to the field, going with the latest version might be how you should proceed.

- 13,723
- 15
- 78
- 104
Be careful before installing new version of python.
Python has no backward compatibility.
Scripts written for python 2.7.* won't work on python 3
For example, print "Hello" will work on python 2.7 but not on version3

- 1
-
"No backwards compatibility" is a stretch - major versions work with all previous versions of that major, e.g. 3.7 will work with 3.4 code. – GetHacked Aug 26 '20 at 16:42