By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

where is sys.path initialized?

P: n/a
Rossum's tutorial states
"Actually, modules are searched in the list of directories given by the
variable sys.path which is initialized from the directory containing
the input script (or the current directory)"

I'm running Python standard installation (ver 2.4) on Windows XP. Where
can I find the "input script" where the sys.path is defined?


Sep 9 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
No one is answering this question. Why, is it a bit unclear or what?
All I wanted to do was to add the path C:\Python24\mypython to the
sys.path so that I could put all my stuff there instead of mixing it
with the stuff that comes with the installation. And I wanted to do it
permanently som that I wouldn't have to use sys.path.append every time
I started Python interpreter.

Here is what I did, and it worked, but I still don't know why. If
somebody has an explanation please tell me.

1. My computer -> Properties->Advanced->Environment variables->System
variables ->New

2. In Variable name field enter PYTHONPATH and in Variable value field
enter C:\Python24\mypython

3. OK, OK, OK to close all the dialog boxes.

4. Restart the computer (it's essential to restart the computer and not
just the Python shell).

5. Open the Python shell and enter
import sys

If you've done exactly as I've described here you should see
C:\Python24\mypython in the list.


Sep 9 '05 #2

P: n/a
Alex wrote:
No one is answering this question. Why, is it a bit unclear or what?

Have patience. No one's getting paid to answer your questions.

Robert Kern

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Sep 9 '05 #3

P: n/a
Alex wrote:
No one is answering this question. Why, is it a bit unclear or what?

No, but if you really expected a response in only four hours you need a
reality check. Many people don't receive Usenet articles for a day or
two, possibly longer, and in any case many people don't *check* their
news more often than once every day or two.

As Robert suggests, have patience. Generally one should wait several
days before giving up on a reply. Reposting is generally less than
useless (basically it's rude), though reposting with more detail or
another way of describing your problem is perfectly acceptable. After a
day or two...

Sep 9 '05 #4

P: n/a
The PYTHONPATH environment variable is good for that. For general
customizing beyond the path, you can make a file called:


and it will be executed every time python runs. It might look like

import sys
sys.path.insert(0, r'C:\Python24\mypython')

Where the tutorial says the sys.path is "initialized from the directory
containing the input script" I think the input script is the file whose
name is the argument to the Python interpreter. E.g., if you ran
"python c:\stuff\" then the path is initialized relative to
c:\stuff. If you just run the interpreter in interactive mode, it's
current working directory when you run 'python'. To say that the path
is initialized "from the directory" I guess only matters if any of the
items in PYTHONPATH or the sys.path are not given as absolute pathnames
but rather relative. If my PYTHONPATH has 'mypython' in it with no
absolute qualifier then in the above scenario where I'm in, say, the
c:\windows directory and I run "python c:\stuff\" it will be
c:\stuff\mypython that is added to the path. I think...

Sep 10 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.