473,387 Members | 1,573 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,387 software developers and data experts.

Manipulating sys.path

Hi all,

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

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.insert(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 859

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

Similar topics

4
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...
3
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...
2
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...
3
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...
3
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...
0
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...
29
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...
4
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">...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.