.pth files

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Aug 9 05:48:11 EDT 2005


On Tue, 09 Aug 2005 09:37:47 +0000, Adriano Varoli Piazza wrote:

> Sylvain Thenault ha scritto:
>> Hi there !
>> 
>> I've some questions regarding pth files (which btw are undocumented in
>> the python reference, is this intentional ?)
>> 
>> I thought that I could use a .pth file to be able to import zope
>> products from both INSTANCE_HOME/Products and
>> ZOPE_HOME/lib/python/Products from outside zope:
>> 
>> 
>> syt at musca:~$ cat cvs_work/Products.pth
>> /home/syt/local/Zope-2.8.1-b1/Products
>> /home/syt/local/Zope-2.8.1-b1/lib/python/Products syt at musca:~$
>> syt at musca:~$ python
>> Python 2.3.5 (#2, Jun 19 2005, 13:28:00) [GCC 3.3.6 (Debian 1:3.3.6-6)]
>> on linux2 Type "help", "copyright", "credits" or "license" for more
>> information.
>> 
>>>>>import sys
>>>>>print sys.path
>> 
>> ['', '/home/syt/cvs_work', '/home/syt/cvs_work/prive/soft',
>>  '/home/syt/local/lib/python2.3/site-packages',
>>  '/home/syt/local/lib/python', '/usr/lib/python23.zip',
>>  '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2',
>>  '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload',
>>  '/usr/local/lib/python2.3/site-packages',
>>  '/usr/lib/python2.3/site-packages',
>>  '/usr/lib/python2.3/site-packages/Numeric',
>>  '/usr/lib/python2.3/site-packages/PIL',
>>  '/usr/lib/python2.3/site-packages/gtk-2.0',
>>  '/usr/lib/python2.3/site-packages/vtk_python', '/usr/lib/site-python']
>> 
>> But as you can see,
>> 1. the Products.pth file isn't considered at all, while for example
>>    PIL.pht in the site-packages is correctly detected
>> 2. I'm not even sure that I can put several paths in a .pth file
>> 
>> Is there a restriction on .pth location ? Is it possible to have
>> multiple path in a pth file ?
>> 
>> 
>  From Learning Python, 2nd Ed:
> "a relatively new feature of Python allows users to add valid directories
> to the module search path by simply listing them, one per line, in a text
> file whose name ends in a .pth suffix.
> 
> See also the docs for the site module in the Python Library reference.

ha, so that's where it's documented ! 
so answer are:
1. Products.pth are only considered in standard site-packages and
   site-python directories
2. yes, it's possible

Now, the question become: why can't we use pth files in other path
specified by the PYTHONPATH environement variable ?

-- 
Sylvain Thénault                               LOGILAB, Paris (France).

http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org





More information about the Python-list mailing list