Python default search paths

Steven D'Aprano steve at
Tue Oct 19 18:35:02 CEST 2010

On Tue, 19 Oct 2010 06:25:30 -0700, swapnil wrote:

> Python allows adding user defined paths to the module search path by
> setting PYTHONPATH environment variable. It also allows to alter the
> location of standard python libraries using PYTHONHOME. But there is no
> way to "only" have user defined paths to python's search paths
> (sys.path)

import sys
sys.path = ['.', 'only', 'user/defined/paths']

Put that in the file given by PYTHONSTARTUP.

> This is useful for embedding applications where it might be desired that
> only user-defined paths are searched for modules.

I doubt that very much. I expect that many things will break if Python 
can't find (e.g.) the sys module. But you might be lucky.


More information about the Python-list mailing list