Python Basic Commands Cheat Sheet
Quick reference for the Python CLI commands used most often in day-to-day development.
Virtual environments
Section titled “Virtual environments”python -m venv .venv # create a virtual environment in .venv/.venv\Scripts\Activate.ps1 # activate (Windows PowerShell).venv\Scripts\activate # activate (Windows CMD)source .venv/bin/activate # activate (macOS / Linux)deactivate # deactivate the current environmentRunning scripts
Section titled “Running scripts”python myscript.py # run a scriptpython -i myscript.py # run then drop into interactive REPLpython -m module_name # run a module as a script (e.g. python -m http.server 8000)python -c "print('hello')" # run a one-linerpython -m pip install requests # install a packagepython -m pip install requests==2.32 # install a specific versionpython -m pip install -r requirements.txt # install from a filepython -m pip install --upgrade requests # upgrade to latestpython -m pip uninstall requests # remove a packagepython -m pip list # list installed packagespython -m pip show requests # details for one packagepython -m pip freeze > requirements.txt # pin current env to a filepython -m pip install --upgrade pip # upgrade pip itselfAlways use python -m pip rather than bare pip. This ensures the package manager runs under the same interpreter as your project, not a different one on the PATH.
Testing and code quality
Section titled “Testing and code quality”python -m pip install pytest ruff black # install the tools into the active venvpython -m pytest # run the test suite (discovers test_*.py files)python -m pytest -k orders -x # only tests matching "orders"; stop at first failurepython -m ruff check . # lint the projectpython -m ruff check . --fix # lint and apply safe automatic fixespython -m ruff format . # format with Ruff's formatterpython -m black . # or format with Black, if the project uses itPick one formatter per project (Ruff’s formatter or Black) and run it in CI with --check so local and CI results match.
Checking versions
Section titled “Checking versions”python --versionpython3 --versionpython -m pip --versionInteractive shell
Section titled “Interactive shell”python # open the REPLexit() # or Ctrl-D (macOS/Linux) / Ctrl-Z Enter (Windows)Common utilities
Section titled “Common utilities”python -m http.server 8000 # simple HTTP server in the current directorypython -m site # show site-packages locationpython -m ensurepip # ensure pip is installedpython -m json.tool file.json # pretty-print a JSON filepython -m py_compile script.py # check syntax without runningEnterprise / private package registry
Section titled “Enterprise / private package registry”python -m pip config set global.index-url https://your-registry-url/python -m pip config set global.trusted-host your-registry-hostpython -m pip config set global.timeout 60Related pages
Section titled “Related pages”- Python install guide — setting up Python 3.14
- Python setup guide — virtual environments and project layout
- Modules and packages — pip and virtual environments in depth
- Python tools — linters, formatters and test runners compared