views:

61

answers:

3

When I enter in python in Terminal it loads up Python 2.6.2. However there are folders by the name of Python 2.6 in different places on my drive. I'm not sure if that's because Python 2.6 has been installed in different places or because Python just likes to have lots of folers in different places.

If there are multiple installations, I could really do with being able to set which one should be used.

+3  A: 

When you run python in a shell or command prompt it will execute the first executable file which is found in your PATH environment variable.

To find out what file is being executed use which python or where python.

Deniz Dogan
Thank you! How do I set `python` to execute a specific installation of Python, instead of just executing the first one it finds?
@cojadate: There is no way to do that as far as I now. What you *can* do is find the `python` executable in your `PATH` environment variable which has the correct version and then make an executable shell script named e.g. `python-2.5` which calls the executable with version 2.5.
Deniz Dogan
+1  A: 

Don't make it complicated. In your ~/.bash_aliases put the following (assuming you are using bash):

alias py26="/usr/bin/python-2.6.1"
alias py30="/usr/bin/python-3.0.0"

Of course, I just made up those paths. Put in whatever is correct for your system. If the ~/.bash_aliases file does not exist, create it.

To use it just type, at the command line, py26 and the appropriate interpreter starts up.

Allen
A: 

From the OS X Python man page (man python):

 CHANGING THE DEFAULT PYTHON

 Using

       % defaults write com.apple.versioner.python Version 2.5

 will make version 2.5 the user default when running the both the python 
 and pythonw commands (versioner is the internal name of the version-
 selection software used).

 To set a system-wide default, replace `com.apple.versioner.python' with
 `/Library/Preferences/com.apple.versioner.python' (admin privileges will 
 be required).

 The environment variable VERSIONER_PYTHON_VERSION can also be used to 
 set the python and pythonw version:

       % export VERSIONER_PYTHON_VERSION=2.5 # Bourne-like shells
            or
       % setenv VERSIONER_PYTHON_VERSION 2.5 # C-like shells
       % python ...

 This environment variable takes precedence over the preference file
 settings.
Charles E. Grant