There’s Python 2.6 installed in the system.
Now I want to use modules introduced in Python 2.7. Because I have no root privilege, I have built & installed 2.7 under my home directory ($HOME/local/)
I added the following to my $HOME/.bashrc:
export PATH=$HOME/local/bin:$PATH
export PYTHONPATH=$HOME/local/lib/python2.7:$PYTHONPATH
Now I encountered the two problems I want ask for workarounds.
1. Invoking Python 2.7
Newly installed Python 2.7 doesn’t find 2.6 modules in system’s library path (/usr/lib/python2.6/site-packages/).
Should I add it to PYTHONPATH manually? Is there any nicer solution?
2. Invoking Python 2.6
Python 2.6 complains at startup:
'import site' failed; use -v for traceback
I guess it’s trying to load 2.7 modules (in $HOME/local/lib/python2.7).
Is it possible to load only 2.6 modules when Python 2.6 is invoked?
Thanks.
1) Invoking python 2.7
In short: don’t do this.
There are reasons why the path is called ‘/usr/lib/python*2.6*/site-packages/’.
One reason is, that in this directory typically the ‘compiled’ python files (.pyc) are stored. python 2.6 and python 2.7 .pyc files are not compatible:
python will skip pyc files which it cannot understood, but you loose at least the benefits of precompiled files.
Another reason is, that things might get mixed up:
I would in your case install the modules needed also for python 2.7 in the python2.7 directory.
2) Invoking python 2.6
You might want to have a look at the part of the man page where PYTHONHOME is described:
You can store the python 2.7 specific files / modules in the appropriate directory in your local installation. Those files / modules will only be picked up when you run the specific version of python. In this case you must not set the PYTHONPATH (or PYTHONHOME).
Note: this is exactly the way Debian (and maybe other distributions) manage different simultaneously installed versions of python.
[Edit: Added section 1 after receiving a comment from niboshi.]