473,386 Members | 1,720 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,386 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 24815
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 directory is 'Z:\\dirA\\Parent\\Child' I want to get...
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 able to upload to a network drive from the intranet...
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 Type "copyright", "credits" or "license()" for...
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 search path. For example: import sys...
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 first line of the main program to make it run in...
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 and I find it great too. Well I would like to have...
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 has a lot of code for now and I've only made...
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 start IDLE... Is there a way to reload the modules...
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: 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
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,...
0
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...

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.