where is sys.path initialized?

Steve M sjmaster at gmail.com
Sat Sep 10 03:47:45 CEST 2005

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\myscript.py" 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\myscript.py" it will be
c:\stuff\mypython that is added to the path. I think...

More information about the Python-list mailing list