Sys.path
sys.path is the ordered sequence of filesystem paths that Python’s import system searches when locating importable modules and packages.
Python Workout: 50 ten-minute exercises
sys.path is the Python list of directory path strings searched by the import system for modules and packages.
- How it is used
- Explains how import locates modules and packages across configured directories.
- How deep it goes
- Defines ordered directory lookup and configuration points, stopping short of detailed import-finder internals.
- Examples
- Uses `import mymod` to demonstrate first-match loading and duplicate-name conflicts.
- What you can do after
- Diagnose module-resolution conflicts by reasoning from sys.path order and distinguishing lookup from cached loading.
Read how Python Workout: 50 ten-minute exercises explains sys.path →
Python Workout, Second Edition
sys.path is the list of directory names that Python searches when locating importable modules and packages.
- How it is used
- Resolves module and package names during import, using an ordered list of directories.
- How deep it goes
- Explains ordered lookup, duplicate-name conflicts, configuration methods, and its boundary with sys.modules.
- Examples
- Uses os, mymod.py, duplicate module directories, and a mypackage directory containing first.py.
- What you can do after
- Diagnose import conflicts and configure module discovery through sys.path, PYTHONPATH, or .pth files.
The Quick Python Book, Fourth Edition
A module search path is the ordered set of directories that a language runtime searches to locate importable modules and packages.
- How it is used
- Controls where Python finds importable modules and packages during program execution.
- How deep it goes
- Explains ordered lookup, initialization sources, execution-context differences, and practical configuration options.
- Examples
- Uses sys.path inspection, a local mymath.py module, shared module directories, and a mymodules.pth file.
- What you can do after
- Operate/configure Python's module discovery by inspecting sys.path and selecting directory, PYTHONPATH, or .pth placement.
Read how The Quick Python Book, Fourth Edition explains sys.path →
Also covered in
- The Well-Grounded Python Developer: How the pros use Python and Flask
- Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi
What to know first
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- moduleA module is a cohesive unit of code or computation that groups related functionality within a larger system and defines a scope or boundary for organizing or sharing it.
Related concepts
- import statementconfigures · An import statement is a source-code declaration that makes definitions from another module, package, or namespace available in the current program context.
- interpreterconfigures · An interpreter is software that evaluates or executes a program or instruction representation according to its defined semantics.
- dependencyused by · A dependency is a component, resource, or prerequisite that another software component or activity relies on to function, build, or proceed.
Questions about sys.path
What is sys.path?
sys.path is the ordered sequence of filesystem paths that Python’s import system searches when locating importable modules and packages.
Which Manning books explain sys.path?
Python Workout: 50 ten-minute exercises, Python Workout, Second Edition and The Quick Python Book, Fourth Edition.
What should I know before learning sys.path?
Manning books that teach sys.path usually introduce function and module first.
What is sys.path part of?
Sys.path is part of sys. sys is a Python standard-library module that exposes interpreter state, standard streams, and system-specific parameters and functions.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


