all Python 3systerm
sys.path
modules
The list of directories Python searches for modules on import. It can be modified to add paths of your own.
Syntax
sys.path # list[str]
The first entry is the directory of the script being run, so your own random.py or json.py sitting next to the code will shadow the standard module — the classic cause of a baffling AttributeError like "module 'random' has no attribute 'randint'". Editing sys.path only affects the current process and is a workaround: for a lasting fix install the package (pip install -e .) or set PYTHONPATH.
Examples
import sys
print(sys.path[:2]) # → ? каталог скрипта и пути стандартной библиотеки
sys.path.append('/my/modules') # искать модули ещё и здесь — в последнюю очередь
sys.path.insert(0, '/priority/path') # искать здесь в первую очередь
print(sys.path[0]) # → /priority/path
See also
Open in the full glossarydocs.python.orgReport an inaccuracy