473,695 Members | 2,384 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.

Jul 18 '05 #1
3 24847
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.


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



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

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

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
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...
by: Ju Hui | last post by:
is python search module by paths in sys.path? how to change it manuallly?
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?
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')
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...
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..
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...
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...
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...
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...
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...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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...
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();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.