[Tutor] Using my own installed python version in my directory tree.

Dave Kuhlman dkuhlman at rexx.com
Wed Sep 13 18:28:03 CEST 2006


On Wed, Sep 13, 2006 at 05:39:13PM +0200, Ziad Rahhal wrote:
> Hi,
> 
> I installed pythin on Linux operating system but on my own tree directory.
> Now I want to get rid (not deleting)
> the default python installation, which means I want my own python version to
> be recognized when I use "python" command.
> 
> PYTHONPATH has nothing to do with that since it just points to modules. I
> tried to set the PATH to $HOME/python/bin but this
> didn't work.
> 
> So in bried I want to use my own installed python version in my directory
> without the need to type $HOME/python/bin... and I want
> to use my own installed python libraries and modules, ignoring the default
> installation.
> 
> How that could be done?

1. The first part of your problem (not typing $HOME/python/bin...
   each time could be solved in either of two ways:

   - Create an alias:

         alias python='$HOME/python/bin/...'

   - Create a symbolic link in a directory that is on your PATH
     *before* the directories containing other pythons:

         ln -s $HOME/python/bin...  python

2. With respect to importing up modules from the correct location,
   if you have installed Python correctly, using your python
   executable will also tell python where to look for modules. I
   also have two Pythons installed on my Linux machine (maybe more,
   I'm not sure).  One is under /usr and the other under
   /usr/local.  When I run /usr/bin/python, it uses the modules
   installed under /usr/lib/python2.4/site-packages/.  And, when I
   run /usr/local/bin/python, it uses modules installed under
   /usr/local/lib/python2.4/site-packages/.

   You can check this by doing something like:

       ~ [5] /usr/bin/python
       Python 2.4.3 (#2, Apr 27 2006, 14:43:58)
       [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
       Type "help", "copyright", "credits" or "license" for more information.
       >>>
       >>> import sys
       >>> sys.path

   which tells you where python looks for modules to be imported.

And, by the way, when you install a python package/module by using:

    $ python setup.py install

python will install the package in the correct location depending
on which python executable you use to do the install.  So, the
following two lines install a module in two different places:

    $ /usr/bin/python setup.py install

    $ /usr/local/bin/python setup.py install

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman


More information about the Tutor mailing list