sys.path in Python Last Updated : 21 Aug, 2024 Comments Improve Suggest changes Like Article Like Report 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.pathsys.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: Python # importing module import sys # printing all directories for # interpreter to search sys.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 Python # importing module import sys # printing all directories sys.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. Python # importing module import sys # appending a path sys.path.append('C:/Users/Vanshi/Desktop') # printing all paths sys.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. Comment More infoAdvertise with us Next Article sys.path in Python V vanshikagoyal43 Follow Improve Article Tags : Python Python-sys Practice Tags : python Similar Reads OS Path module in Python OS Path module contains some useful functions on pathnames. The path parameters are either strings or bytes. These functions here are used for different purposes such as for merging, normalizing, and retrieving path names in Python. All of these functions accept either only bytes or only string obje 2 min read Pathlib module in Python Pathlib module in Python offers classes and methods to quickly perform the most common tasks involving file system paths, incorporating features from several other standard modules like os.path, glob, shutil, and os.Path classes in Pathlib module are divided into pure paths and concrete paths. Pure 6 min read Python | os.path.join() method The os.path.join() method is a function in the os module that joins one or more path components intelligently. It constructs a full path by concatenating various components while automatically inserting the appropriate path separator (/ for Unix-based systems and \ for Windows). ExamplePythonimport 4 min read Posixpath Module in Python The posixpath module is a built-in Python module that provides functions for manipulating file paths in a way that adheres to the POSIX standard. This module abstracts the differences in path handling between various operating systems, including Unix-like systems (e.g., Linux, macOS) and Windows. Im 3 min read Python | os.path.size() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system-dependentthe functionality. os.path module is a submodule of the OS module in Python used for common path 2 min read Like