brain storm
brain storm

Reputation: 31242

which version of python is used when I run it in interpreter?

I am confused in trying to understand which python version is used when I run them in interpreter? That is, how the shell decides which python version to load when I have more than one versions. I have snapshot of my /usr/bin. It has atleast two different python versions2.5 and 2.6. I have not specified anything in my .bashrc to choose which one from. when I execute python command on bash shell, python interpreter opens up, but loads with version 2.6. How is this detected by shell? If I want to change versions, how will I do that? That is, I want to change the default version lastly what kind of files are these in /usr/bin/python. I tried to open them in editor and I see some @@@. I have read many posts here but some makes me confusing.

ls /usr/bin/python
python            python2.5         python2.6         pythonw           pythonw2.6        
python-config     python2.5-config  python2.6-config  pythonw2.5   

python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Upvotes: 0

Views: 1151

Answers (2)

fedorqui
fedorqui

Reputation: 289485

To know which version is used by default, type

which python

To use another one, use the full path when invoking them:

/usr/bin/python/python2.5 myfile.py
/usr/bin/python/python2.6 myfile.py
etc.

If you want to change the default, you can create an alias in ~/.bashrc for example:

my_python='/usr/bin/python/python2.7'

or better change the link direction of /usr/bin/python (or whatever comes from which python). It is a link, so link it to the exact version you need.

ln -s /prefered/path/of/python /usr/bin/python

The files you see in /usr/bin/python are executables. You can do the following to see this:

file /usr/bin/python/python2.5

In my case:

$ file /usr/bin/python
/usr/bin/python: symbolic link to `python2.7'
$ file /usr/bin/python2.7
/usr/bin/python2.7: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xf66a10f2c444b2329b25ab6790abb7fbb4fe3f78, stripped

Upvotes: 2

ShaBANG
ShaBANG

Reputation: 193

python --version

Then head on over to your .bashrc (should be in your home directory) and add:

alias python='[your path]'

for me I have:

alias python='/usr/bin/python2.7'

Just make sure you say:

source ./bashrc

to apply your changes.

Upvotes: 1

Related Questions