Sys is a built-in Python module that contains parameters specific to the system i.e. it contains variables and methods that interact with the interpreter and are also governed by it.
sys.path
sys.path is a built-in variable within the sys module. It contains a list of directories that the interpreter will search in for the required module.
When a module(a module is a python file) is imported within a Python file, the interpreter first searches for the specified module among its built-in modules. If not found it looks through the list of directories(a directory is a folder that contains related modules) defined by sys.path.
Initializing sys.path
There are three ways to specify a path :
- DEFAULT- By default, the interpreter looks for a module within the current directory. To make the interpreter search in some other directory you just simply have to change the current directory. The following example depicts a default path taken by the interpreter:
Python3
# importing moduleimport sys # printing all directories for # interpreter to searchsys.path |
Output:

- THROUGH ENVIRONMENT VARIABLES- An environment variable that contains the path an interpreter can take while looking for modules can be employed. Once set, it hints interpreter with directories to locate a module. The following example shows how this can be done.
PYTHONPATH=C:\Users\Vanshi\Desktop
Python3
# importing moduleimport sys # printing all directoriessys.path |
Output:

- APPENDING PATH- append() is a built-in function of sys module that can be used with path variable to add a specific path for interpreter to search. The following example shows how this can be done.
Python3
# importing moduleimport sys # appending a pathsys.path.append('C:/Users/Vanshi/Desktop') # printing all pathssys.path |
Output:

Note that the first string returned by path is always empty this is to indicate the interpreter to check in the current directory.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

