473,757 Members | 10,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 24851
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
3263
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 a string which up like 'Z:\\dirA\\Parent' Then I do a sys.path.append('Z:\\dirA\\Parent') The code I have written below does all this.. but I have a feeling there is a better way to do this.. Please can someone help me. import os
2
6063
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 server. On the line: dirs = Directory.GetDirectories(currentDir) I get "Access to the path "\\les-net\les\Special Projects\ATSPDF" is denied." How do I get the GetDirectories command to user my user ID and password when it tries to hit the...
19
40723
by: Ju Hui | last post by:
is python search module by paths in sys.path? how to change it manuallly?
2
1537
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 more information. IDLE 1.2b3 --- Question: How did I end up with the second item in path?
1
1375
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 sys.path.append('path to my modules')
5
10428
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 Jython, it fails to find some of the imported modules. These are just plain Python imports of code I wrote myself in another directory. Apparently Jython does not use the PYTHONPATH environment variable. I created an environment variable called...
4
1739
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 all my modules in the path when I'm using textmate AND when I use the commandline (ipython), but because textmate and the command line use different python versions they also search in different places..
3
12299
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 interface. So I've tried to split code into separate files and in windows as I remember worked file when i wrote eg. import myFile but now in Ubuntu it says Module not found. (I'm using Ubuntu and I've installed python 2.5 and wxPython 2.8.4, and I'm...
4
1970
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 folders in sys.path without logging out and back in? something like "source .cshrc" in a shell...
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10072
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...
1
9885
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,...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
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
6562
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
3829
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
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
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.