
Python commands: Learn common Python terminal commands for checking versions, isolating dependencies, installing packages and running scripts. This guide explains what each command does, its syntax, practical examples, useful options, and common mistakes. Commands are shown for typical installations; flags can vary across operating-system and tool versions.
Before you start
Open a terminal appropriate for the operating system shown in the examples. Check that the required tool is installed and that you are running it with the permissions needed for your task. Replace sample names, paths, hostnames and IDs with values from your own environment.
Syntax at a glance
Square brackets usually indicate optional arguments, while uppercase words such as FILE, HOST and PACKAGE are placeholders that you replace. Keep quotes around paths or text that contains spaces. Commands should be tested on a safe sample before being used in production.
Quick command reference
| Command | What it does | Example | Useful options |
|---|---|---|---|
python --version | Show the Python interpreter version | python3 --version | On some systems use python3 explicitly |
python -m venv | Create an isolated virtual environment | python -m venv .venv | Activation differs by shell and operating system |
python -m pip install | Install a Python package | python -m pip install requests | --upgrade updates a package; -r requirements.txt reads pinned requirements |
python SCRIPT.py | Run a Python script | python app.py --help | -m runs a module; -u disables stdout buffering |
python -m http.server | Serve a folder over HTTP for local testing | python -m http.server 8000 | -d DIRECTORY selects a directory in supported versions |
Command syntax and examples explained
1. python --version
Purpose: Show the Python interpreter version.
Syntax
python --versionExample
python3 --versionOptions and notes: On some systems use python3 explicitly.
Use the same interpreter for installing packages and running the project.
2. python -m venv
Purpose: Create an isolated virtual environment.
Syntax
python -m venv DIRECTORYExample
python -m venv .venvOptions and notes: Activation differs by shell and operating system.
A venv isolates project packages from the system interpreter.
3. python -m pip install
Purpose: Install a Python package.
Syntax
python -m pip install PACKAGEExample
python -m pip install requestsOptions and notes: --upgrade updates a package; -r requirements.txt reads pinned requirements.
Prefer a virtual environment and trusted package names.
4. python SCRIPT.py
Purpose: Run a Python script.
Syntax
python SCRIPT.py [ARGS]Example
python app.py --helpOptions and notes: -m runs a module; -u disables stdout buffering.
Check the script source before running code downloaded from the internet.
5. python -m http.server
Purpose: Serve a folder over HTTP for local testing.
Syntax
python -m http.server [PORT]Example
python -m http.server 8000Options and notes: -d DIRECTORY selects a directory in supported versions.
This simple server has no authentication; do not expose it to untrusted networks.
Common mistakes and troubleshooting
- Command not found: confirm the tool is installed and available on your PATH; open a new terminal after changing PATH.
- Permission denied: verify the current account, file permissions and target path. Use administrator/root privileges only when genuinely required.
- Unexpected output: check the command version, quoting, current directory and exact arguments. Consult the local help or manual for options supported by your build.
- Destructive operations: preview the target and keep a backup before deleting data, rewriting history, flashing a partition or changing system configuration.
Safety tips
Review every command before running it, especially commands that delete files, change permissions, flash firmware, alter a database or expose a network service. For network scanning and remote administration, work only on devices and systems you own or are authorized to test. Keep credentials, private keys, access tokens and log files private.
Frequently asked questions
Do these commands work on every system?
Not always. Some commands are specific to Windows, Linux, Android, a particular package manager or an installed tool version. Use the syntax shown for your platform and check local help when a flag is unavailable.
Can I copy and run every example exactly?
Use the examples as templates. Replace placeholders such as filenames, package IDs, hostnames and paths with your own values, and verify the effect before executing a command that changes data or system state.
Conclusion
Use this reference as a starting point, then confirm flags in the tool’s official help or manual for your installed version. A clear understanding of syntax, options and side effects makes command-line work more reliable.