-m flag
The interpreter option python -m name, which finds a module on the module search path and runs it as a program.
In more detail
python -m pip, python -m venv, python -m idlelib and python -m pytest run tools as modules of the exact interpreter you typed, avoiding PATH confusion. Running your own package with python -m mypkg.main keeps its imports working.
Example
python -m pip install requestsRelated terms
- module search path — The list of folders Python searches, in order, when a program imports a module.
- pip — Python's standard package installer, which downloads packages from the Python Package Index and installs them.
- virtual environment — A self-contained folder with its own Python and its own installed packages, so each project's packages stay separate.
Taught in
- Installing Python On A Mac — Hands-on Python: Complete Video Course & Book
- Installing Python On Linux — Hands-on Python: Complete Video Course & Book
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- Packages, And Your Own Library — Hands-on Python: Complete Video Course & Book
- Virtual Environments — Hands-on Python: Complete Video Course & Book
- Shipping: scripts, entry points and git — Hands-on Python: Complete Video Course & Book