472,353 Members | 978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

sys.path.append('/my/new/path')

Is it possible to append a new Path to some file permanently? It seems like a
sys.path.append('/my/new/path') statement is temporary.

In other words, where and in what file on a Win32 box or Linux box is the sys.path info kept. I
have a couple of paths I keep practice files in I want to add to the path permanently.

Thanks
Jul 18 '05 #1
3 24720
Jeff Wagner wrote:
Is it possible to append a new Path to some file permanently? It seems like a
sys.path.append('/my/new/path') statement is temporary.


Use the PYTHONPATH environment variable.

--irmen

Jul 18 '05 #2
Jeff Wagner wrote:
Is it possible to append a new Path to some file permanently? It seems
like a sys.path.append('/my/new/path') statement is temporary.

In other words, where and in what file on a Win32 box or Linux box is the
sys.path info kept. I have a couple of paths I keep practice files in I
want to add to the path permanently.


The easiest way to extend the list of paths is to put a .pth file (a text
file with an arbitrary name, the .pth extension containing one path per
line) in the site-packages directory. For details, see

http://www.python.org/doc/current/inst/search-path.html

Peter

Jul 18 '05 #3
From the Python doc:

The most convenient way is to add a path configuration file to a
directory that's already on Python's path, usually to the
..../site-packages/ directory. Path configuration files have an extension
of .pth, and each line must contain a single path that will be appended
to sys.path. (Because the new paths are appended to sys.path, modules in
the added directories will not override standard modules. This means you
can't use this mechanism for installing fixed versions of standard
modules.)

Paths can be absolute or relative, in which case they're relative to the
directory containing the .pth file. Any directories added to the search
path will be scanned in turn for .pth files. See site module" >the
documentation for the site module for more information.

A slightly less convenient way is to edit the site.py file in Python's
standard library, and modify sys.path. site.py is automatically imported
when the Python interpreter is executed, unless the -S switch is
supplied to suppress this behaviour. So you could simply edit site.py
and add two lines to it:
import sys
sys.path.append('/www/python/')

However, if you reinstall the same major version of Python (perhaps when
upgrading from 2.2 to 2.2.2, for example) site.py will be overwritten by
the stock version. You'd have to remember that it was modified and save
a copy before doing the installation.

There are two environment variables that can modify sys.path. PYTHONHOME
sets an alternate value for the prefix of the Python installation. For
example, if PYTHONHOME is set to "/www/python", the search path will be
set to ['', '/www/python/lib/python2.2/',
'/www/python/lib/python2.3/plat-linux2', ...].

The PYTHONPATH variable can be set to a list of paths that will be added
to the beginning of sys.path. For example, if PYTHONPATH is set to
"/www/python:/opt/py", the search path will begin with ['/www/python',
'/opt/py']. (Note that directories must exist in order to be added to
sys.path; the site module removes paths that don't exist.)

Finally, sys.path is just a regular Python list, so any Python
application can modify it by adding or removing entries.
visit my homepage at http://www.homepages.lu/pu/
Jul 18 '05 #4

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

Similar topics

3
by: Golawala, Moiz M (GE Infrastructure) | last post by:
Hi all, What I am trying to do is write some generic code where I can get the path of the parent directory. for example if current working...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be...
19
by: Ju Hui | last post by:
is python search module by paths in sys.path? how to change it manuallly?
2
by: Dr. Pastor | last post by:
I installed Python 2.5 on Windows XP. I got the following system that works well. --- Python 2.5b3 (r25b3:51041, Aug 3 2006, 09:35:06) on win32...
1
by: Frank | last post by:
Hi, I want to create some modules to use them in my programs. Now the problem is, how to add the path to these modules permanently to the python...
5
by: Russ | last post by:
I have a Python program that I want to run in Jython so I can get Java bytecode output. The program runs fine in Python, but when I change the...
4
by: andrea | last post by:
Hi everyone, I use python on macosx with textmate as editor (great program). I also use macport to install unix programs from the command line...
3
by: SMALLp | last post by:
Hy! I'm new in Linux, and i feel little less newer in python. I need advice and help. I'm making an application witch purpose is irrelevant. It...
4
by: Python | last post by:
Hi there, I moved a few modules into the modules folder (on OSX: /opt/local/lib/ python2.5/site-packages/). They don't show up though when I...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.