sys is a module which contains a lot of usefull functions. To make use of sys module in a python program, it has to be imported and this is done using "import sys". Not to be confused with sus. Answer from YehKyaHogya on reddit.com
🌐
Python
docs.python.org › 3 › library › sys.html
sys — System-specific parameters and functions
See sys.monitoring for details. ... A dictionary of the various implementation-specific flags passed through the -X command-line option. Option names are either mapped to their values, if given explicitly, or to True. Example: $ ./python -Xa=b -Xc Python 3.2a3+ (py3k, Oct 16 2010, 20:14:50) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-sys-module
Python sys Module - GeeksforGeeks
August 1, 2025 - Helps in debugging and managing system-level behavior in Python scripts. The sys module controls program input, output and error streams, enabling precise data handling beyond standard input and print functions.
Discussions

What's the application of "import sys"?
sys is a module which contains a lot of usefull functions. To make use of sys module in a python program, it has to be imported and this is done using "import sys". Not to be confused with sus. More on reddit.com
🌐 r/learnpython
3
2
September 19, 2021
For what uses do we need `sys` module in python? - Stack Overflow
I'm a bit experienced without other languages but, novice with Python. I have come across made codes in jupyter notebooks where sys is imported. I can't see the further use of the sys module in the More on stackoverflow.com
🌐 stackoverflow.com
Tricks with `sys.modules`?
Its documentation says: This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. What kind of tricks? One I’ve seen here is that sys.modules['_decimal'] = None before importing the decimal ... More on discuss.python.org
🌐 discuss.python.org
0
0
March 5, 2024
What does "from sys import argv" mean?
The documentation goes into a little more detail, but essentially: argv is a list containing all the command line arguments passed into the python script you're currently running. The first entry in the list is the name of the script that you're running. You can see this by writing the following python script: from sys import argv print(argv) Save that file as argv_test.py. Now, when you run it like this: python argv_test.py, the result will be ['argv_test.py'] , because you're running the script with no arguments, so argv has only one argument; the name of the script itself. But if you run: python argv_test.py one two three, then the result will be ['argv_test.py', 'one', 'two', 'three'] Why this is useful is because often you might find yourself writing a script that does something based on an argument the user provides, like reading all of the files in a given directory. In this case you might use argv to hold the user inputs to the script. You don't use from sys import random because sys contains functionality related to interacting with the python interpreter, whereas random contains functionality related to random numbers. Because they're separate concerns, they're held in separate built-in modules -- otherwise you'd just have one giant module, sys, which would get hard to organise. More on reddit.com
🌐 r/learnpython
4
2
May 28, 2019
🌐
Sunysb
insti.physics.sunysb.edu › ITP › computing › doc › python › python-texinfo › sys.html
sys -- Python library reference
A list of strings giving the names of all modules that are compiled into this Python interpreter. (This information is not available in any other way --- sys.modules.keys() only lists the imported modules.)
🌐
W3Schools
w3schools.com › python › ref_module_sys.asp
Python sys Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... import sys print(f'Python version: {sys.version}') print(f'Platform: {sys.platform}') Try it Yourself »
🌐
Python 101
python101.pythonlibrary.org › chapter20_sys.html
Chapter 20 - The sys Module — Python 101 1.0 documentation
>>> import sys >>> print(sys.path) ['', 'C:\\Python27\\Lib\\idlelib', 'C:\\Python27\\lib\\site-packages\\setuptools-0.9.5-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\sphinx-1.2b3-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\docutils-0.11-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pygments-1.6-py2.7.egg', 'C:\\Windows\\system32\\python27.zip', ' C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\wx-2.9.4-msw']
Find elsewhere
🌐
Linux Manual Page
linux.die.net › diveintopython › html › file_handling › more_on_modules.html
6.4. Using sys.modules
>>> import fileinfo >>> print '\n'.join(sys.modules.keys()) win32api os.path os fileinfo exceptions __main__ ntpath nt sys __builtin__ site signal UserDict stat >>> fileinfo <module 'fileinfo' from 'fileinfo.pyc'> >>> sys.modules["fileinfo"] <module 'fileinfo' from 'fileinfo.pyc'> The next example shows how to use the __module__ class attribute with the sys.modules dictionary to get a reference to the module in which a class is defined.
🌐
Altcademy
altcademy.com › blog › what-is-import-sys-in-python
What is import sys in Python
March 3, 2024 - The sys module gives you access to some variables used or maintained by the interpreter and functions that interact strongly with the interpreter. It's like having a backstage pass to the Python show, allowing you to see and modify aspects of ...
🌐
Python documentation
docs.python.org › 3 › tutorial › modules.html
6. Modules — Python 3.14.3 documentation
It is initialized to a default path taken from the environment variable PYTHONPATH, or from a built-in default if PYTHONPATH is not set. You can modify it using standard list operations: >>> import sys >>> sys.path.append('/ufs/guido/lib/python')
🌐
Quora
quora.com › What-does-import-sys-mean-in-Python
What does [import sys] mean in Python? - Quora
In Python one uses the import statement to access these modules. The sys module is included in the standard libraries and contains the functions and other data necessary for your code to perform introspection about the system in which its running.
🌐
Medium
medium.com › @gokulg.me › python-sys-module-from-beginner-to-advanced-b0f6bc73c8c2
Python sys Module: From Beginner to Advanced | by Gokul G | Medium
February 26, 2025 - Whether you're handling command-line arguments, modifying the Python path, or managing output streams, the sys module is essential for system-level operations. To use the sys module, you must first import it: import sys ·
Top answer
1 of 3
171

How python finds its modules

Strictly taken, a module is a single python file, while a package is a folder containing python files, accompanied by a (can be empty) file named __init__.py, to tell python it is a package to import modules from. In both cases, modules need their .py extension, but importing them is done without (see further below).

By default, Python looks for its modules and packages in $PYTHONPATH.

To find out what is included in $PYTHONPATH, run the following code in python (3):

import sys
print(sys.path)

How to add a directory

Occasionally

From within a python file, you can add path(s) occasionally to the default path by adding the following lines in the head section of your python application or script:

import sys
sys.path.insert(0, "/path/to/your/package_or_module")

For example:

if I have a folder: /home/myname/pythonfiles, and I want to import the file module_1.py, located in that directory, I add this to the head section of my code:

import sys
sys.path.insert(0, "/home/myname/pythonfiles")

And I can simply import the file module_1.py by:

import module_1

When I create a package and want to import module(s) from the package, I need to create a folder in $PYTHONPATH, containing the modules, accompanied by a (can be empty) file called __init__.py

For example:

To import from a package (folder) called my_package in /home/myname/pythonfiles , add the /home/myname/pythonfiles path to your $PYTHONPATH, like in example 1, and import the module called module_2.py (inside the package folder) simply with: `

from <packagename> import module_2

Adding directories to $PYTHONPATH permanently:

Add the following line to your ~/.profile file.

export PYTHONPATH=$PYTHONPATH:/path/you/want/to/add

Subdirectories

From within a package, subdirectories are not included just like that; you need to "chain" the directories. To import a module module_3.py, inside folder subfolder inside folder packagename:

import packagename.subfolder.module_3

Given the fact that all subfolders in the package include their own __init__.py file.

When a module is in the same directory as the script or application

There is no need to insert the path to a module when it is in the same directory as the script or application, it is automatically added.

Example:

If I have a folder, containing script.py and module.py, I can simply import the module by:

import module
2 of 3
7

The correct way to use relative import is:

from ..Common import foo1

And you also need a __init__.py in all your folders.

🌐
GeeksforGeeks
geeksforgeeks.org › python › uses-of-os-and-sys-in-python
Uses of OS and Sys in Python - GeeksforGeeks
July 23, 2025 - In this example, below code uses the `os` module to retrieve the value of the "USERNAME" environment variable, typically representing the current user's username. It then prints the obtained username. Python3 · import os # Get the value of an environment variable username = os.getenv("USERNAME") print("Username:", username) ... In this example, below code uses the `sys` module to access command-line arguments.
🌐
Medium
medium.com › pythons-gurus › python-sys-module-beginner-guide-e7585684c26c
Python sys Module essential Intro Guide | Python’s Gurus
June 7, 2024 - This command tells Python to load the sys module and make its features available to your program. Once imported, you can leverage the various capabilities of the sys module to manage command-line arguments, interact with the interpreter and handle input/output operations efficiently.
🌐
Python Geeks
pythongeeks.org › python geeks › learn python › python sys module
Python sys Module - Python Geeks
July 30, 2021 - It is a built-in language and comes ready to use in the Python Standard Library. sys is a sub-module of the OS module. We need to import the sys module using an import statement to use the functions that are available in the module.
🌐
Python Course
python-course.eu › applications-python › sys-module.php
1. sys-Module | Applications | python-course.eu
April 6, 2022 - To change the way the interpreter prints interactively entered expressions, you will have to rebind sys.displayhook to a callable object. We will demonstrate this in the following interactive example session: >>> import sys >>> s = "cheese" >>> s 'cheese' >>> def my_display(x): ...
🌐
Python.org
discuss.python.org › python help
Tricks with `sys.modules`? - Python Help - Discussions on Python.org
March 5, 2024 - Its documentation says: This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. What kind of tricks? One I’ve seen here is that sys.modules['_decimal'] = None before importing the decimal module apparently prevents importing the C version of the module so that the Python version gets used.
🌐
O'Reilly
oreilly.com › library › view › python-standard-library › 0596000960 › ch01s13.html
The sys Module - Python Standard Library [Book]
May 10, 2001 - Using the sys Module to Get Script Arguments · File: sys-argv-example-1.py import sys print "script name is", sys.argv[0] if len(sys.argv) > 1: print "there are", len(sys.argv)-1, "arguments:" for arg in sys.argv[1:]: print arg else: print ...
Author   Fredrik Lundh
Published   2001
Pages   304
🌐
Python documentation
docs.python.org › 3 › reference › import.html
5. The import system — Python 3.14.3 documentation
A direct call to __import__() performs only the module search and, if found, the module creation operation. While certain side-effects may occur, such as the importing of parent packages, and the updating of various caches (including sys.modules), only the import statement performs a name binding ...