A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/sys-path-in-python/ below:

sys.path in Python - GeeksforGeeks

sys.path in Python

Last Updated : 21 Aug, 2024

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 :

Python
# importing module
import sys

# printing all directories for 
# interpreter to search
sys.path

Output:

PYTHONPATH=C:\Users\Vanshi\Desktop
Python
# importing module
import sys

# printing all directories
sys.path

Output:

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.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4