python3 - an interpreted, interactive, object-oriented programming language
python3 [-c command | -m module | script] [arguments]
Options you will use
-c command- Run the Python code in command.
-m module- Run a library module as a script: -m venv DIR, -m pip, -m pytest, -m json.tool FILE, -m py_compile FILE.
-V, --version- Print the version and exit.
-u- Unbuffered stdout and stderr - log lines show up at once under systemd and Docker (or PYTHONUNBUFFERED=1).
-B- Do not write .pyc files.
-i- Inspect interactively after running the script.
-I- Isolate: ignore PYTHON* variables and the user site directory.
-W ARG- Warning control, e.g. -W error.
-X OPT- Implementation-specific options, e.g. -X importtime.
-u- Unbuffered stdout and stderr - log lines show up at once under systemd and Docker (or PYTHONUNBUFFERED=1).
-B- Do not write .pyc files.
-i- Inspect interactively after running the script.
-I- Isolate: ignore PYTHON* variables and the user site directory.
-W ARG- Warning control, e.g. -W error.
-X OPT- Implementation-specific options, e.g. -X importtime.
Examples
$ python3 -m venv .venvCreate a virtual environment (needs the python3-venv package on Ubuntu).
$ source .venv/bin/activatePut the venv first on PATH, so python and pip mean the venv ones.
$ python3 healthcheck.py --timeout 2 http://localhost:8080/actuator/healthRun a script with arguments.
$ python3 -m json.tool pods.jsonPretty-print JSON.
Gotchas
- Ubuntu marks the system interpreter as externally managed (PEP 668): pip refuses to install into it. Use a venv per tool, or pipx for applications.
Taught in
Try python3 in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.