views:

155

answers:

2

Hi, I have locally installed a newer version of Python. For that I did the following:

$ cd
$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz
$ tar xvzf Python-2.6.2.tgz
$ cd Python-2.6.2
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install

In .bash_profile I put the following:

export PATH=$HOME/opt/bin/:$PATH
export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH

And than I executed:

$ cd
$ source .bash_profile
$ python -V

It worked. I got a new working versions of Python. However, now I would like to try something with my old version, which is a "global" version installed by root for all users. Can anybody, pleas, tell me how I can do it?

P.S. I tired to remove changes in .bash_profile. I have commented the 2 last lines which were added when I installed the new version. So, now I have the following .bash_profile file:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

#export PATH=$HOME/opt/bin/:$PATH
#export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH

And I source the new version of the file (source .bash_profile). But I still get the old version of Python. When I type "Python -V" I get "Python 2.6.2".

A: 

Undo your changes to .bash_profile and execute source .bash_profile.

Hank Gay
I tried that. It did not work (I added more details in my original question).
Verrtex
+1  A: 

You can directly call the program with something like "/usr/local/bin/python myscript.py". You just need to know where your standard installation of python is. If you don't know, you can undo your changes and then type "which python" to find out what actually gets executed when you type "python" on the command line".

For example:

$ /usr/bin/python -V
Python 2.3.4
$ /usr/bin/python2.4 -V
Python 2.4.4
$ /opt/local/bin/python2.7 -V
Python 2.7a0
$ python -V
Python 2.5.2
$ which python
/usr/bin/python

To make things easier you can also create aliases:

$ alias python2.4=/usr/bin/python2.4
$ alias python2.5=/usr/bin/python2.5
$ python2.4 -V
Python 2.4.4
$ python2.5 -V
Python 2.5.2

Aliases make it pretty easy for you to run different versions of python. Place them in your .bashrc file so they are always defined.

Bryan Oakley