'python' Bash command doesn't link to 2.1.1

Richard Jones richard at bizarsoftware.com.au
Wed Aug 15 21:00:03 EDT 2001


On Thursday 16 August 2001 07:54, Harry George wrote:
> An alternative, allowing you to run several different verisons of
> python:
>
> as root edit a file "/usr/local/bin/py21":
> #---edit------------
> export PYTHONHOME=/usr/local
> export
> PYTHONPATH=${PYTHONHOME}/lib/python2.1:${PYTHONHOME}/lib/python2.1/site-apc
>kages ${PYTHONHOME}/bin/python2.1 $@
> #---end edit-----------
> and do
>    chmod +755 py21
> 
> Then you can run python 2.1 stuff with "py21" and python 1.5.2 with
> "python".  This may be important if some system scripts depend on one
> version or the other.

You don't actually need to jump through these hoops.
Python 1.5.2 will have had its library files installed in /usr/lib/python1.5. 
Python 2.1.1 will have had its library files installed in /usr/lib/python2.1.

Python 1.5.2 will never look in 2.1's lib directory, and vice-versa. It 
doesn't matter where the python binary is located, or what it's called, the 
PYTHONHOME of "/usr" is hard-coded as the place to look for the library 
directory if no other directory is supplied.

Note that if the directory that python is in contains a lib/python<version>/ 
directory, this will be used as the default search path (hence you can test 
python when it's built but not installed).

Also, if python is in /home/richard/bin/python, and 
/home/richard/lib/python<version> exists, that will be used as the default 
search path.

I'm not sure what the "minimal" set of modules/directories are required for 
/home/richard/lib/python<version> to be recognised though.

Python's quite smart about these things...

>From the python man page (the only reference I could find regarding search 
paths...)

       PYTHONPATH
              Augments  the default search path for module files.
              The format is the same as the shell's $PATH: one or
              more directory pathnames separated by colons.  Non-
              existant directories  are  silently  ignored.   The
              default  search path is installation dependent, but
              generally begins with ${prefix}/lib/python<version>
              (see PYTHONHOME above).  The default search path is
              always appended to $PYTHONPATH.  If a script  argu­
              ment  is given, the directory containing the script
              is inserted in the path in  front  of  $PYTHONPATH.
              The  search  path  can be manipulated from within a
              Python program as the variable sys.path .


    Richard




More information about the Python-list mailing list