473,666 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Manipulating sys.path

Hi all,

I want to manipulate sys.path outside of PYTHONPATH (environment) and
sys.path.append () (programmatical ly).

A bit of background:
We're maintaining a small application that includes a couple of Python
scripts. Over time, a decent amount of code has been forked into
modules, so the overall file system layout of our kit looks like this:

tool/
bin/
prog1.py
prog2.py
...
lib/
pack1/
mod1.py
mod2.py
...

The issue I have is that I want to add the 'lib' directory to the module
search path so that our programs prog1.py, prog2.py,... can find the
modules pack1.mod1, pack1.mod2, ... But I want to keep this out of the
program's source code which rules out statements like
'sys.path.inser t(0, "../lib")'. We also want to be minimal-invasive for
the hosting environment, so no copying of 'lib' into the standard Python
lib directories (like /usr/local/lib/python2.5/site-packages etc.), nor
forcing the user to change his PYTHONPATH shell environment. It should
be solved locally in our kit's directory tree.

I was thinking about putting code into a 'bin/__init__.py' file but
that's only working for modules and not for executable scripts, right?!
Then I came across the '.pth' files, but unfortunately they only seem to
work in some standard paths (like the before mentioned
/usr/local/lib/python2.5/site-packages), and not in the script directory
(like 'bin' in my case) which is automatically added to sys.path.

Can anybody think of something that could be of help here?

Thanks,
Thomas
Jul 9 '08 #1
0 866

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

Similar topics

4
22937
by: Michael J. Astrauskas | last post by:
Does anyone have a function for manipulating GET variables in a URL? I want to be able to modify some parameters without affecting others. An example of what I'm looking for: Let's say the current url is: www.mine.com/home.php?name=joe&page=7&theme=blue I want to be able to run a function like: $newurl = change_get($_SERVER,"page","6"); and end up with:
3
1398
by: Laszlo Zsolt Nagy | last post by:
Hi All, I need to create a daemon that sits on a server and forwards some e-mails. (Well not only that, it needs to change header information before forwarding and also insert messages into a database). The mailbox module is fine but I do not see a way to delete/add messages - it is ready only. The other possiblity is IMAP4 but it is bad because my program should not store passwords for all users. I can only see one solution right now:
2
2409
by: Shane Suebsahakarn | last post by:
Hi all, Does anyone have any idea why creating a table link across a network should be so slow? My front end app follows these steps when opening: * Retrieve all linked tables in the current database as a recordset from the MSysObjects table. * For each record: Check the existance of the mdb file that the table resides in. If the mdb file exists, check the table exists by opening the target
3
1586
by: Newbie | last post by:
I am trying to insert items to an xml file: 1. Search for the right node where the new item is to be added as a child. 2. Add the new item with its attributes. I am looking at XPathNavigator and XMLReader but cant find the functions to do the job. Suggestions are welcome. Thanks in advance.
3
1600
by: genc_ ymeri at hotmail dot com | last post by:
Hi, I have some text files and all I need is to look for a certain word a replace it with another one. What is the best way of doing this ? Thank You very much for any tip, G.Y. PS: I'm trying not to rewrite the entire file but as soon as I get the wanted word just replace that word and quit from that process...
0
1017
by: John | last post by:
Hi all, I currently have an app which renders images onto a page by simply pointing towards the path. What is the easiest/quickest/best way for me to render these same images within a page but to change the page to allow zoom control? Regards John.
29
3257
by: Halid Umar A M | last post by:
Hi All, I m Halid Umar, network security research student. I will explain my situation and give me hint if you can. I expect reply from you all. * I have to handle numbers that have more than 64 bit like 128bit in cryptography applications. * For example, if i want to add two 128 bit numbers what should i do in C.
4
3252
by: Jean-François Michaud | last post by:
Hello, I've been looking at this for a bit now and I don't see what's wrong with the code. Can anybody see a problem with this? Here is an XSLT snippet I use. <xsl:template match="graphic"> <xsl:param name="path" /> <fo:block padding-after="12pt">
0
8363
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
8883
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
8787
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8561
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6203
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
5672
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();...
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
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.