Complete Python commands reference — 73 commands across 4 categories. Quick reference cheat sheet for Windows, Mac & Linux.
This page covers the command-line surface of Python itself — the flags you pass to the interpreter — and the install options of pip, which is where most day-to-day trouble happens. Neither has many options that matter, but the ones that do decide which files run, which Python they run in, and whether a broken environment can be rescued.
| Shortcut | Action |
|---|---|
| python -c <command> | Execute the Python code in command |
| python -m <module-name> | Locate the module using the standard import |
| python - | Read commands from standard input (sys.stdin) |
| python <script> | Execute the Python code contained in script, which must be a filesystem path |
| Shortcut | Action |
|---|---|
| python -? | Print a short description of all command line |
| python --help-env | Print a short description of Python-specific |
| python --help-xoptions | Print a description of implementation-specific -X |
| python --help-all | Print complete usage information and exit |
| python -V | Print the Python version number and exit |
| Shortcut | Action |
|---|---|
| python -b | Issue a warning when converting bytes or bytearray |
| python -B | If given, Python won't try to write.pyc files |
| python --check-hash-based-pycs default | Control the validation behavior of hash-based.pyc |
| python -d | Turn on parser debugging output (for expert only) |
| python -E | Ignore all PYTHON* environment variables, e.g |
| python -i | Enter interactive mode after execution |
| python -I | Run Python in isolated mode |
| python -O | Remove assert statements and any code conditional |
| python -OO | Do -O and also discard docstrings |
| python -P | Don't prepend a potentially unsafe path to sys.path |
| python -q | Don't display the copyright and version messages |
| python -R | Turn on hash randomization |
| python -s | Don't add the user site-packages directory |
| python -S | Disable the import of the module site |
| python -u | Force the stdout and stderr streams to be unbuffered |
| python -v | Print a message each time a module is initialized |
| python -x | Skip the first line of the source, allowing use |
| python -X | Reserved for various implementation-specific options |
| Shortcut | Action |
|---|---|
| pip install -r <file> | Install from the given requirements file |
| pip install -c <file> | Constrain versions using the given constraints file |
| pip install --build-constraint <file> | Constrain build dependencies using the given |
| pip install --requirements-from-script <file> | Install dependencies of the given script file |
| pip install --no-deps | Don't install package dependencies |
| pip install -e <path/url> | Install a project in editable mode (i.e |
| pip install --dry-run | Don't actually install anything, just print what |
| pip install -t <dir> | Install packages into <dir> |
| pip install --platform <platform> | Only use wheels compatible with <platform> |
| pip install --python-version <python_version> | The Python interpreter version to use for wheel |
| pip install --implementation <implementation> | Only use wheels compatible with Python |
| pip install --abi <abi> | Only use wheels compatible with Python abi <abi> |
| pip install --user | Install to the Python user install directory |
| pip install --root <dir> | Install everything relative to this alternate root |
| pip install --prefix <dir> | Installation prefix where lib, bin and other |
| pip install --src <dir> | Directory to check out editable projects |
| pip install -U | Upgrade all specified packages to the newest |
| pip install --upgrade-strategy <upgrade_strategy> | Determines how dependency upgrading should |
| pip install --force-reinstall | Reinstall all packages even if they are already |
| pip install -I | Ignore the installed packages, overwriting them |
| pip install --ignore-requires-python | Ignore the Requires-Python information |
| pip install --no-build-isolation | Disable isolation when building a modern source |
| pip install --check-build-dependencies | Check the build dependencies |
| pip install --break-system-packages | Allow pip to modify an EXTERNALLY-MANAGED Python |
| pip install -C <settings> | Configuration settings to be passed to the build |
| pip install --compile | Compile Python source files to bytecode |
| pip install --no-compile | Do not compile Python source files to bytecode |
| pip install --no-warn-script-location | Do not warn when installing scripts outside PATH |
| pip install --no-warn-conflicts | Do not warn about broken dependencies (environment |
| pip install --require-hashes | Require a hash to check each requirement against |
| pip install --progress-bar <progress_bar> | Specify whether the progress bar should be used |
| pip install --root-user-action <root_user_action> | Action if pip is run as a root user [warn, ignore] |
| pip install --report <file> | Generate a JSON file describing what pip did |
| pip install --group <[path:]group> | Install a named dependency-group |
| pip install --no-clean | Don't clean up build directories |
| pip install -i <url> | Base URL of the Python Package Index |
| pip install --extra-index-url <url> | Extra URLs of package indexes to use in addition |
| pip install --no-index | Ignore package index (only looking at --find-links |
| pip install -f <url> | If a URL or path to an html file, then parse |
| pip install --uploaded-prior-to <datetime_or_duration> | Only consider packages uploaded prior to the given |
| pip install --pre | Include pre-release and development versions |
| pip install --all-releases <release_control> | Allow all release types (including pre-releases) |
| pip install --only-final <release_control> | Only allow final releases (no pre-releases) |
| pip install --no-binary <format_control> | Do not use binary packages |
| pip install --only-binary <format_control> | Do not use source packages |
| pip install --prefer-binary | Prefer binary packages over source packages, even |
python <script> runs a file and python -c <command> runs a one-line expression, but the flag to learn is python -m <module-name>: it runs a module as a script from the interpreter's own environment, so python -m pip, python -m venv and python -m http.server always use the Python you invoked rather than whatever is first on PATH. python -i drops into a REPL after the script finishes with its variables intact, which is the cheapest debugger there is. python -u unbuffers stdout and is what container logs need to show output promptly.
python -I runs in isolated mode — no user site-packages, no PYTHON* environment variables, no script directory on the path — and is the right way to run system tools that must not be affected by a user's packages. python -E and python -s apply those restrictions separately. python -v prints every module import, which answers "which file is actually being imported" when two copies of a package exist. python -O strips asserts and python -B stops writing .pyc files. python -X carries implementation options such as -X dev for extra runtime checks and -X importtime for a startup profile.
pip install -r <file> installs a requirements file and pip install -c <file> pins versions from a constraints file without installing them, which is how a team keeps one lockfile across projects. pip install -e <path/url> installs a project in editable mode so source edits take effect without reinstalling — the standard setup for a package you are developing. pip install -U upgrades, pip install --dry-run shows what would change first, and pip install --no-deps installs a single package without touching its dependencies. pip install --user installs into the user directory when a system Python is not writable; a virtual environment is the better fix.
It guarantees pip runs in the same interpreter as python. Plain pip may belong to a different Python on PATH, which is the usual cause of "installed but import fails".
Run it with python -i script.py. When the script ends or raises, you get a prompt with its namespace loaded.
pip install -e . links the project source into site-packages instead of copying it, so changes are live without reinstalling.
python -v prints each import with its path, or run python -c "import x; print(x.__file__)".
Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"