I think you probably have two options, barring a reinstallation of 2.7, which might be the easiest thing to do.
You can include the following first line in every Python script:
#!/usr/local/bin/python2.6
Change the path to reflect the version and location of the Python you would like to use.
Alternately you could create a bash alias like:
alias python = '/path/to/pythonversion'
I would go with the first version myself.
While there are obviously differences in the different versions of Python, there are also differences between the "system" Python and those you install via Python.org, MacPorts, Homebrew, etc. All of these "additional" versions can coexist quite happily with the system versions in /System/Library/Frameworks/Python.framework/Versions
- I have 2.3, 2.5.6, 2.6.7, and 2.7.2 on my 10.8.4 iMac which originally came with Lion installed. /usr/bin/python
is 2.7.2.
Basically, there is no good reason to get rid of any of the system Pythons (they only take up ~200MB), and some very good reasons to not get rid of them. They are included for a reason, and there are various system utilities and programs that depend on them. You could get strange, unexplained behavior if you remove them, and vital stuff may not work, as Python scripts and libraries are behind some major system tools. Python has been designed to have multiple versions living happily side-by-side, so if your system is set up properly (which I generally trust the Apple engineers to have done), there won't be any conflicts as hypothesized by another answer.
If you want to change which version of Python runs by default when you type python
into the Terminal prompt, then change your $PATH
environment variable to point toward your installation of choice, do not unlink or change /usr/bin/python
. For example, I use MacPorts, so /opt/local/bin
is ahead of /usr/bin
in my $PATH
, so I never run the "system" version 2.7.2. You can then start your scripts with
#!/usr/bin/env python
and it will search your path for the correct binary.
You should have no problems at all using MacPorts point to your version of choice. One thing I would suggest, though, is to keep /opt/local/bin/python
pointing to the latest version of Python 2 (2.7.5, currently), and use /opt/local/bin/python3
point to 3.3.2. Yes, you have to remember to add the 3
on the end of the command, but several months back I tried setting python
to Py3, and occasionally would get weird errors from some programs expecting Py2 to be there.
Hopefully this helps answer your actual question, please let me know if you need anything else.
Best Answer
It is possible to have multiple different python installations on macOS. And the user is able to choose where they are installed.
For example, I have the standard Python that comes with macOS, as well as one that came with Anaconda that I use for my Python development.
To make things easier, I linked my system Python to Anaconda's Python interpreter. However, this does not delete the Python version in my system's library, merely stops linking against it.
If you're ever confused which interpreter is being used to run your code in terminal, I find a simple way to find out is to simply type the Terminal command "which python". That will quickly output the location of the Python interpreter being used by your system by default. In my case it outputs "/anaconda/bin/python".