Question

I'm new to python, and I find that to see the import search paths, you have to import the sys module and than access the list of paths using sys.path, if this list is not available until I explicitly import the sys module, so how the interpreter figure out where this module resides. thanks for any explanation.

Was it helpful?

Solution

The module search path always exists, even before you import the sys module. The sys module just makes it available for you.

It reflects the contents of the system variable $PYTHONPATH, or a system default, if you have not set that environment variable.

OTHER TIPS

There is a default search path within the interpreter. (https://docs.python.org/2/install/#modifying-python-s-search-path )

A default value for the path is configured into the Python binary when the interpreter is built.

BTW, sys is built into the Python interpreter. (https://docs.python.org/2/tutorial/modules.html#standard-modules)

One particular module deserves some attention: sys, which is built into every Python interpreter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top