473,626 Members | 3,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.pth files

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@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@musca:~$
syt@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 ?

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

http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Aug 9 '05 #1
6 5056
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@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@musca:~$
syt@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.

--
Adriano Varoli Piazza
The Inside Out: http://moranar.com.ar
MSN: ad*******@hotma il.com
ICQ: 4410132
Aug 9 '05 #2
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@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@musca:~$
syt@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
Aug 9 '05 #3

[Sylvain]
I've some questions regarding pth files (which btw are undocumented in the
python reference, is this intentional ?)


http://google.com/search?q=site:docs.python.org%20pth

The first hit explains how .pth files work (although it's the sort of
documentation that makes Xah Lee explode with fury).

--
Richie Hindle
ri****@entrian. com
Aug 9 '05 #4
Richie Hindle wrote:
http://google.com/search?q=site:docs.python.org%20pth

The first hit explains how .pth files work (although it's the sort of
documentation that makes Xah Lee explode with fury).


That just makes it all the more delicious.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
There is another world, which is not of men.
-- Li Bai
Aug 9 '05 #5
Sylvain Thenault wrote:
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@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@musca:~$
syt@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
informatio n.

>>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 ?

Hello,

I've been doing some work on that recently, if your do want to
include .pth files specified by a different location then you have to do
some work, here are a couple of solutions:

* Site.py is prompted to load a sitecustomise.p y file which is
located in the Lib directory - if it is there. This file is
automatically executed on the start up of python. Here you can
look for a command line argument (or a local config file) passed
in - you can then go and find the .pth file yourself. The code to
pull in .pth stuff is located in the site.py file - you can import
this function and use it but I don't do that for two reasons
(instead I pull across my own copy - effectivly freezing that
implementation) :

1. You are creating a circular reference
2. I can find no docs or imformation about using the functions
in the site.py file so therefore I have to assume that the
functions in the site.py file are not designed to be used
this way and therefore shouldn't be relied upon to be stable
or even present across python releases (I'm a conservative
programmer.

This however can be problematic if you are managing a large
number of client installs as you will need to have a local file on the
local box - thereby making upgrading the clients installs difficult.

* I created a python module which can receive command line arguments
setting up site-package directories and pythonpath which executes
as a file, this also receives an argument of which python file to
execute after this. This means that the file which does this work
can be located anywhere (ie on your company server) - making
release management easier. However this solution requires more work.
* You could copy the java method using zip files with a manifest in
the same way Java uses jar files - I say could because I havn't
done this but it is the way I distribute Java apps - nice and
clean, also installed my own JRE with my program - that way I have
complete control (anyone that complains about using hard drive
space can go back to using their ZX81 :-)) over my environment.
If you are not worried about managing the release stuff and
sitecustomise works fine for you then this is the way to go as it is the
simplest (less code means more reliable). However be aware that the
sitepackage directory on the python install will automatically be
included and you could have two versions of the same package in
sys.path. Finally, one last thing - beware if you are on windows as
some path information is written in the registry and this is included
automatically.

Cheers,

Neil

--

Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany

Tel : +49 (0)351 4173 154
e-mail : be**@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com

Aug 9 '05 #6
Neil Benn wrote:
* Site.py is prompted to load a sitecustomise.p y file which is
located in the Lib directory - if it is there. This file is
automatically executed on the start up of python. Here you can
look for a command line argument (or a local config file) passed
in - you can then go and find the .pth file yourself. The code to
pull in .pth stuff is located in the site.py file - you can import
this function and use it but I don't do that for two reasons
(instead I pull across my own copy - effectivly freezing that
implementation) :

1. You are creating a circular reference
The "import sitecustomize" stuff is placed effectively at the end of
site.py, so it should be quite safe to "import site" from your
sitecustomize.p y file and use the functions there.
2. I can find no docs or imformation about using the functions
in the site.py file so therefore I have to assume that the
functions in the site.py file are not designed to be used
this way and therefore shouldn't be relied upon to be stable
or even present across python releases (I'm a conservative
programmer.


While I can't fault your caution, we've been using a few things in
site.py from sitecustomize for a while with no problems (across releases
from Python 1.5.2 to Python 2.4). The functions are documented in the
site.py source itself, of course, at least in a cursory fashion, and
while there have been changes over versions, I don't recall anything
causing breakage. Normally I'd quite agree about staying away, but for
something like this (i.e. not a core part of an application, but
something to set up the environment instead) I'd say "go for it".

-Peter
Aug 9 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14159
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip Smarty-2.6.7.tar.gz on a system running WindowsXP SP2. Apache and PHP tested out fine. After adding Smarty, I ran the following http://localhost/testphp.php
44
4030
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are identical with which. Write a program that prints out which file are redundant copies. Here's the spec. -------------------------- The program is to be used on the command line. Its arguments are one or
0
6116
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
18
3163
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now you have your ".cpp" files all ready, without any "#include" or "#define" in them. Let's assume that there's 2 source files in this project, "a.cpp" and
3
3087
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by using header file. i can create a class c1 with f1() in c1.h and include this c1.h in file1.cpp by giving the statement #include "c1.h" tell me that what exactly is the difference between c1.h and c1.cpp? Since they both are doing the same things.
11
5573
by: ambika | last post by:
Iam just trying to know "c". And I have a small doubt about these header files. The header files just contain the declaration part...Where is the definition for these declarations written??And how does that get linked to our program when we run it??I would appreciate any helpful info..And I would like to thank you for that in advance -ambika
22
3001
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text files, which in turn could be simply and easily maintained with notepad. I understand the benefits of XML, really, but in the case of configuration files it seems it is almost always nothing more than unnecessary complexity, both in accessing them...
18
2290
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or JPG files. The problem as I see it - if you know the name of the file, you could download it off the server (currently we are using an HTTP/Get but I'm going to be using WebClient in the new version.) If there any way to password protect the...
0
1506
by: wal | last post by:
How does one attach files to emails using libgmail? The following code http://pramode.net/articles/lfy/fuse/4.txt works fine when said files are simple text files, but it failes as soon as the files are wild binary files, even attaching the source of an email in a text file (.eml files) failes. What am I missing here? Any hints? The output I get when attemting to send binary files using the code above is pasted below. have fun,
3
5176
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8203
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.