473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

.pth files in working directory

My goal is to have the top level of a directory tree in the Python
path without touching anything outside the directory. I tried to
create .pth files with the top level path in every subdirectory
but this doesn't work despite working directory being part of the
Python path.

Creating the pth file in .../site-packages works but I prefer to
have everything inside the directory tree so that removing the tree
is sufficient for a complete uninstall. Any hints are appreciated,
thanks.

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
Aug 31 '05 #1
6 3607
Peter Maas wrote:
My goal is to have the top level of a directory tree in the Python
path without touching anything outside the directory. I tried to
create .pth files with the top level path in every subdirectory
but this doesn't work despite working directory being part of the
Python path.

Creating the pth file in .../site-packages works but I prefer to
have everything inside the directory tree so that removing the tree
is sufficient for a complete uninstall. Any hints are appreciated,
thanks.


Not sure from the above description exactly what it is you want, but
generally such non-standard sys.path and .pth manipulations are best
handled by a sitecustomize.py file, possibly which makes its own calls
to site.addsitedir() and such. Try "help(site)" for more.

In this case, I think you'd have a sitecustomize.py which looks for .pth
files in the current directory and calls site.addsitedir(), but I'm not
sure. Maybe if this doesn't work, an example would clarify things.

-Peter
Aug 31 '05 #2
Peter Hansen schrieb:
Not sure from the above description exactly what it is you want,
I want a tree

top/
install.py
sub1/
__init__.py
mod1.py
sub2/
mod2.py

where I can do "from sub1 import mod1" in mod2.py no matter what the
absolute path of top is. To achieve this I start install.py once to
retrieve the absolute dir of itself (= abspath of top/) and creates
..pth files with its absolute dir in every subdirectory.
but
generally such non-standard sys.path and .pth manipulations are best
handled by a sitecustomize.py file, possibly which makes its own calls
to site.addsitedir() and such. Try "help(site)" for more.


But sitecustomize.py changes the Python installation, doesn't it?
This wouldn't be an advantage over putting a .pth file into
..../site-packages.

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
Aug 31 '05 #3
On Wed, 31 Aug 2005 15:07:41 +0200
Peter Maas <pe***@somewhere.com> wrote:
I want a tree

top/
install.py
sub1/
__init__.py
mod1.py
sub2/
mod2.py

where I can do "from sub1 import mod1" in mod2.py no matter what the
absolute path of top is. To achieve this I start install.py once to
retrieve the absolute dir of itself (= abspath of top/) and creates
.pth files with its absolute dir in every subdirectory.


If top/ is the working directory for your Python interpreter, the
problem is solved automatically. Python puts the current working
directory in the default search path. So, if you run

python sub2/mod2.py

then it would work.

HTH,
-Michael
Aug 31 '05 #4
Peter Maas wrote:
Peter Hansen schrieb:
generally such non-standard sys.path and .pth manipulations are best
handled by a sitecustomize.py file, possibly which makes its own calls
to site.addsitedir() and such. Try "help(site)" for more.


But sitecustomize.py changes the Python installation, doesn't it?
This wouldn't be an advantage over putting a .pth file into
.../site-packages.


You can have a local sitecustomize.py in the current directory, which
wouldn't change the Python installation. Would that help?

As far as I can tell, the current directory isn't added to the sys.path
until after site.py executes, so I don't believe you can rely on .pth
files to do anything like what you want. Sitecustomize.py is it, with
appropriate smarts inside.

-Peter
Aug 31 '05 #5
Michael Ekstrand schrieb:
If top/ is the working directory for your Python interpreter, the
problem is solved automatically. Python puts the current working
directory in the default search path. So, if you run


IIS sets the the site path as working directory. So I would probably
have to change wd at the beginnig of every module. Each module would
read the top location from a .pth file in its directory. Yes that's
possible. Thanks for your help.

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
Aug 31 '05 #6
Peter Hansen schrieb:
Peter Maas wrote:
But sitecustomize.py changes the Python installation, doesn't it?
This wouldn't be an advantage over putting a .pth file into
.../site-packages.

You can have a local sitecustomize.py in the current directory, which
wouldn't change the Python installation. Would that help?


I think this is what I need. Thanks, Peter.

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
Aug 31 '05 #7

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

Similar topics

7
by: lawrence | last post by:
2 Questions: 1.) Can anyone think of a way to speed up this function? It is terribly slow. I plan to reduce the number of directories to 3, which I guess will speed it up in the end. 2.) This...
7
by: MAK | last post by:
Hello everyone, I know how to add images and icons etc to dll file. What I would like to know is there is a way to add those icons on the forms during the run time from the dll or to reference it ...
4
by: Hal Vaughan | last post by:
I am writing out archive files using ZipOutputStream with the following code: aEntry is a global Array of ZipEntries llData is a LinkedList of the data corresponding to the the ZipEntry of the...
6
by: Peter Row | last post by:
Hi, Can someone give me a set of steps for an ASP.NET project (well actually its just a VB.NET class DLL that implements HttpHandler) that will work when moved to another developers machine? ...
4
by: Steffen Loringer | last post by:
Hi all, which of the asp.net files on my development system must be transfered to the "final" server system to make the application working? And which of the "Directory" option in IIS need to be...
4
by: Jerry | last post by:
I'm having just a bit of trouble wrapping my brain around the task of working with folders that are above the site's root folder. I let users upload photos (.jpg/.gif files) which can...
17
by: Kerr | last post by:
Hi all, I am sure that this is quite simple but can't find any good examples anywhere. I need a method of copying multiple files from a source directory to a destination directory. The file...
18
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...
3
by: Ray | last post by:
Hi all, I'm running PHP 5.2.0 on my Windows XP laptop, running under IIS. I have files named 'config.php' in two different web applications on this machine, which are included throughout each...
1
by: Claire | last post by:
Ive written a small string resource building utility that I send out to our translators. I have a setup project for each language we support, which picks out a group of 12 english resx files plus...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.