Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

Python - .pth files?

 
Thread Tools Search this Thread
Old 03-22-2005, 04:29 PM   #1
insyte@gmail.com
 
Posts: n/a
Default .pth files?

I'm unclear on how .pth files work. Some posts imply they can be
arbitrarily named, as long as they include the .pth extension, and can
exist anywhere in the current sys.path. Other documentation seems to
imply that they must be named <package>.pth, although I'm not sure what
"package" it would be named after.

I used strace to see if I could see which files it was looking for, but
the output didn't show a single attempted stat() or open() of any .pth
files.

I may be barking up the wrong tree with the .pth files, anyway. Is
there a general "best practice" for appending additional directories to
search for modules? Specifically, I frequently write utilities that
depend on a shared module or two that I don't particularly want to
stick in the "site-packages" directory. The layout I generally prefer
is a "lib" dir in the same directory as the assorted scripts. Clearly,
I could just do a 'sys.path.append["./lib"]', but that seems kludgy.

Any clarifications or recommendations?

Thanks!

-Ben

  Reply With Quote
Old 03-22-2005, 05:52 PM   #2
Skip Montanaro
 
Posts: n/a
Default Re: .pth files?


Ben> I'm unclear on how .pth files work. Some posts imply they can be
Ben> arbitrarily named, as long as they include the .pth extension, and
Ben> can exist anywhere in the current sys.path. Other documentation
Ben> seems to imply that they must be named <package>.pth, although I'm
Ben> not sure what "package" it would be named after.

<package>.pth naming is just a convention so you can easily sort out the
association for each of multiple pth files. I have a mojam.pth file but no
"mojam" package on my server. Works just fine.

Skip
  Reply With Quote
Old 03-22-2005, 06:48 PM   #3
Ben Beuchler
 
Posts: n/a
Default Re: .pth files?

On Tue, 22 Mar 2005 12:52:28 -0600, Skip Montanaro <> wrote:

> <package>.pth naming is just a convention so you can easily sort out the
> association for each of multiple pth files. I have a mojam.pth file but no
> "mojam" package on my server. Works just fine.


Interesting.

Where does it call home? site-packages?

-Ben
  Reply With Quote
Old 03-23-2005, 03:26 AM   #4
Peter Hansen
 
Posts: n/a
Default Re: .pth files?

wrote:
> I'm unclear on how .pth files work. Some posts imply they can be
> arbitrarily named, as long as they include the .pth extension, and can
> exist anywhere in the current sys.path. Other documentation seems to
> imply that they must be named <package>.pth, although I'm not sure what
> "package" it would be named after


This is pretty trivial to experiment with. Two minutes
would make it clear that the name of the file is irrelevant.
So would skimming the source in site.py, though I've found
that takes more like five minutes to piece together as it's
not particular self-documenting and has, as I recall, few
helpful inline comments.

> I used strace to see if I could see which files it was looking for, but
> the output didn't show a single attempted stat() or open() of any .pth
> files.


site.py does not look everywhere, just in a specific,
pre-defined, and platform-specific set of folders, again
defined in the source site.py (I think the written docs
on this miss a few cases). It also looks in any folders
that are added to the sys.path as a result of being
found in a .pth file (i.e. the search for .pth files is
basically recursive).

> I may be barking up the wrong tree with the .pth files, anyway. Is
> there a general "best practice" for appending additional directories to
> search for modules? Specifically, I frequently write utilities that
> depend on a shared module or two that I don't particularly want to
> stick in the "site-packages" directory. The layout I generally prefer
> is a "lib" dir in the same directory as the assorted scripts. Clearly,
> I could just do a 'sys.path.append["./lib"]', but that seems kludgy.
>
> Any clarifications or recommendations?


Look into sitecustomize.py perhaps? Or PYTHONPATH settings
with a wrapper shell script to set it just for the utilities
in question?

Or do the sys.path.append thing, since it works, is fairly
common practice, and is pretty explicit.

-Peter
  Reply With Quote
Old 03-23-2005, 04:52 AM   #5
Bengt Richter
 
Posts: n/a
Default Re: .pth files?

On 22 Mar 2005 09:29:39 -0800, "" <> wrote:

>I'm unclear on how .pth files work. Some posts imply they can be
>arbitrarily named, as long as they include the .pth extension, and can
>exist anywhere in the current sys.path. Other documentation seems to
>imply that they must be named <package>.pth, although I'm not sure what
>"package" it would be named after.
>
>I used strace to see if I could see which files it was looking for, but
>the output didn't show a single attempted stat() or open() of any .pth
>files.
>
>I may be barking up the wrong tree with the .pth files, anyway. Is
>there a general "best practice" for appending additional directories to
>search for modules? Specifically, I frequently write utilities that
>depend on a shared module or two that I don't particularly want to
>stick in the "site-packages" directory. The layout I generally prefer
>is a "lib" dir in the same directory as the assorted scripts. Clearly,
>I could just do a 'sys.path.append["./lib"]', but that seems kludgy.
>
>Any clarifications or recommendations?
>
>Thanks!
>

I haven't looked at all the ("about 23") hits, but have you tried googling for

pth siteython.org/doc

? The first hit looks promising.

(BTW, for your next python question, try some relevant words in place of "pth" before posting

Regards,
Bengt Richter
  Reply With Quote
Old 03-24-2005, 01:58 AM   #6
Skip Montanaro
 
Posts: n/a
Default Re: .pth files?

>> I have a mojam.pth file but no "mojam" package on my server. Works
>> just fine.


Ben> Where does it call home? site-packages?

Yup.
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Video files to PSP ivan DVD Video 4 06-17-2008 10:16 AM
How to copy *.vob files on DVD to the hard disk and merge them together zengpeiwen1719 Software 0 05-24-2008 09:33 AM
Convert Video files to MP4 for iPod ivan DVD Video 0 04-26-2006 07:38 AM
Very slow recognising DVD disc Terry Pinnell DVD Video 1 03-28-2006 05:53 PM
Now I introduce some popular software of multimedia eightsome@gmail.com DVD Video 0 03-28-2006 01:29 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47