20+ essential Python commands you should know
On many Linux distributions, the python command doesn't exist at all until you install it, and python3 is the one that works.
Python is one of the most popular programming languages in the world, and it ranks near the top of every Stack Overflow Developer Survey. It's a powerful yet simple language that you can use for almost anything, from scripts and automation to web apps, data analysis, and AI.
Thanks to tools like Jupyter Notebook, Google Colab, and online editors, you can start writing Python without installing anything. But as soon as you build real projects, you'll need the command-line interface (CLI) to install Python and packages, create virtual environments, run your code, and deploy it.
Many developers find the CLI one of the most intimidating parts of learning Python. The good news is that a few commands cover most of what you'll do every day. In this article, you'll learn the most useful commands for Python development on Windows, macOS, and Linux. The Linux and macOS commands were tested with Python 3.13 and 3.15.
What is the command-line interface?#
The command-line interface, or CLI, is a text-based program that lets you run programs and work with your operating system (OS), for example, to create and manage files.
A CLI accepts commands you type in the form of text and passes them to a shell, a command interpreter. The shell runs each command and shows you its result, called the output.
These two terms are often confused, so here's the difference:
- The CLI, or terminal, is the window where you type commands and see their output.
- A shell is the program inside it that interprets your commands, such as Bash, zsh, or PowerShell.
The Python interpreter has its own interactive shell too. When you run python3 (or python on Windows) with no arguments, you get the >>> prompt, where each line you type runs as Python code.
Do you need the CLI in Python development?#
To be an effective Python developer, and especially a full-stack developer, you need a solid knowledge of the command line. Most backend frameworks, such as Django and FastAPI, are run and managed from the command line, and so are tools like Git and Docker. If you connect to a remote server over SSH, the command line is all you have.
Python is also a great language for building your own CLI tools, with libraries like argparse (built in), Click, and Typer. Once you're comfortable using the command line, you can start creating command-line apps yourself.
The CLI skills you learn here also carry over to other languages, such as PHP, JavaScript, and Java.
Introduction to the CLI#
How you open and use the command line depends on your OS. Here's how to get started on the three operating systems developers use most: Windows, macOS, and Linux.
Windows#
On Windows, open Windows Terminal, which comes with Windows 11, and use PowerShell, its default shell. You can also use the older Command Prompt (cmd).
Windows uses \ in paths instead of /, so keep that in mind when you navigate directories. PowerShell includes aliases for many Unix commands, such as ls, cp, mv, rm, cat, and pwd, so most navigation commands below work in PowerShell too. Where cmd needs a different command, we show it.
You can also install Git for Windows, which includes Git Bash, a terminal that runs the Bash shell on Windows, so the Unix commands in this article work as written. Another option is the Windows Subsystem for Linux (WSL), which runs a full Linux distribution on Windows.
macOS#
On macOS, open the Terminal app. You can search for it with Spotlight (Cmd + Space) or find it in the Utilities folder inside Applications. The default shell is zsh.
Linux#
On Linux, the terminal app depends on your distribution and desktop, but the shortcut Ctrl + Alt + T opens it on most of them. The default shell is usually Bash.
Now you should have a window similar to this one:

20+ most useful CLI commands for Python development#
With your terminal open, it's time to look at the commands that make your life as a Python developer much easier.
Installation commands#
There are many ways to install Python, but installing it from the command line is often the quickest, and it makes updates easier too.
1. py install (Windows)
On Windows, the recommended way to install Python is now the Python install manager, which replaces the traditional installer. You can get it from the Microsoft Store, or install it with WinGet, the package manager built into Windows:
winget install 9NQ7512CXL7T -e --accept-package-agreements --disable-interactivityThen use the py command to install the Python version you want, and list the versions you have:
py install 3.15
py listAfter that, run python or py to start your latest Python version. If you have the old Python launcher installed, uninstall it first, since both provide a py command.
2. Homebrew and pyenv (macOS)
macOS no longer comes with Python 2, and the python3 command it includes belongs to Apple's Command Line Tools, which ship an older Python 3. To install current versions, use Homebrew, a package manager for macOS. Install it with the command from its website:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"You can then install the latest Python with brew install python. If you work on projects that need different Python versions, use pyenv, which installs and switches between versions:
brew install pyenvFollow the instructions pyenv prints to add it to your shell, which for zsh means adding these lines to your ~/.zshrc file:
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - zsh)"Open a new terminal, then install a version and set it as your default:
pyenv install 3.15 # Installs the latest 3.15 release
pyenv global 3.15 # Makes it your default pythonNow, python and python3 run the version you set with pyenv:
python --version
# Python 3.15.2pyenv also works on Linux. On Windows, use the Python install manager or pyenv-win.
3. apt, dnf, and pacman (Linux)
Most Linux distributions come with Python 3 installed, because many system tools are written in it. If yours doesn't, or you need extra components, use your distribution's package manager.
On Debian-based distributions, such as Ubuntu and Linux Mint, use apt:
sudo apt update
sudo apt install python3 python3-venv python3-pipThe python3-venv and python3-pip packages add virtual environments and pip, which Debian and Ubuntu package separately.
On many Linux distributions, the python command doesn't exist at all until you install it, and python3 is the one that works. On Debian and Ubuntu, you can make python run Python 3 with:
sudo apt install python-is-python3On Fedora and other RPM-based distributions, such as Red Hat Enterprise Linux, use dnf:
sudo dnf install python3On Arch-based distributions, use pacman:
sudo pacman -S pythonYour distribution's Python version can be a few releases behind the latest one. To use the newest Python on Linux, use pyenv or uv, which you'll see below.
Interpreter and package commands#
Next, let's look at the python command itself and the tools that install packages.
4. python
On macOS and Linux, the command is usually python3. On Windows, it's python or py. In the examples below, use whichever works on your system.
To run a Python file, call the interpreter followed by the file name:
python3 helloworld.pyTo see the available options, use the help flag:
python3 -h
python3 --helpTo print the version of Python you're running:
python3 -V
python3 --versionTo run Python code without creating a file, use the -c flag:
python3 -c "print('Hello, World!')"
# Hello, World!The -m flag runs a module as a script. For example, this creates a virtual environment with the built-in venv module, which you'll learn more about below:
python3 -m venv .venvRun python3 with no arguments to open the interactive shell. To leave it, type exit (or exit() in versions before Python 3.13), or press Ctrl + D on macOS and Linux, or Ctrl + Z then Enter on Windows.
5. pip
pip installs packages from the Python Package Index (PyPI), along with the packages they depend on. Use it inside a virtual environment, as shown in the virtual environments section below.
To install the latest version of a package, run pip install with its name:
pip install djangoTo install a specific version:
pip install django==5.2To keep track of a project's dependencies, list them in a requirements file. The -r flag installs every package in the file:
pip install -r requirements.txtThe pip freeze command prints the packages installed in your environment, with their exact versions. To save them to a requirements file, redirect the output with >:
pip freeze > requirements.txtUse >, not >>. A single > replaces the file's contents, while >> appends to the file, so running it twice would list every package twice.
Note that on recent versions of Debian and Ubuntu, Homebrew's Python, and other systems that follow PEP 668, running pip install outside a virtual environment fails with an externally-managed-environment error. This protects the Python that your system tools depend on. Install packages in a virtual environment instead, use your OS package manager for system-wide packages, or use pipx for command-line tools.
6. pipx
Some Python packages are command-line tools you want to use everywhere, not only in one project, such as HTTPie, Black, or virtualenv. pipx installs each one in its own virtual environment and makes its command available in your terminal:
pipx install httpieInstall pipx itself with your package manager, for example, brew install pipx on macOS or sudo apt install pipx on Debian and Ubuntu. Then run pipx ensurepath once, so your shell can find the tools it installs.
7. uv
uv is a fast, all-in-one tool for Python projects. It installs Python versions, creates virtual environments, manages dependencies, and runs tools, replacing pip, venv, pipx, and pyenv in many workflows. Install it with the command from its documentation, or with brew install uv or pipx install uv.
To install a Python version:
uv python install 3.15To start a new project, add a dependency, and run code in the project's environment:
uv init myapp
cd myapp
uv add requests
uv run myapp
# Hello from myapp!uv init creates a pyproject.toml file and a src/myapp package with a main() function, which uv run myapp calls. uv add installs the package in the project's .venv and records it in pyproject.toml and a uv.lock lock file. uv run runs any command inside the project's environment without activating it first, so uv run python script.py works too.
To run a command-line tool once without installing it, use uvx, for example, uvx --from httpie http --version.
Permission commands#
Python is great for scripting and working with files. For these tasks, you need to know how permissions work on your OS.
8. sudo
On macOS and Linux, some tasks, such as installing system packages, need administrator (root) permissions. The sudo command runs a single command as an administrator, after asking for your password:
sudo apt install python3-venvAvoid sudo pip install. Installing Python packages as root can break the Python your OS depends on, and it's blocked on most current systems anyway. Use a virtual environment, pipx, or uv instead.
On Windows 11, version 24H2 and later, you can turn on Sudo for Windows in Settings > System > Advanced, and then run commands as an administrator the same way:
sudo netstat -abOn older versions of Windows, open the terminal as an administrator instead, or use a tool like gsudo.
9. chmod
chmod changes the permissions of files and directories on macOS and Linux. A common use is to make a Python script executable.
First, add a shebang line at the top of the script, so the system knows to run it with Python:
#!/usr/bin/env python3
print("Hello from a script")Then make the script executable:
chmod +x myscript.pyNow you can run it directly with ./:
./myscript.py
# Hello from a scriptWithout chmod +x, running ./myscript.py fails with a "Permission denied" error.
Navigation and file commands#
Working with files and directories from the terminal is an everyday task. Here are the essential commands.
10. ls, dir
To list the contents of a directory, use ls on macOS, Linux, and PowerShell, or dir in cmd:
ls # Lists the current directory
ls mydirectory # Lists another directoryThe -a flag also shows hidden files, whose names start with a dot, such as .venv or .gitignore. The -l flag shows the permissions, owner, size, and modification date of each file. You'll often see them combined:
ls -alOn Windows, dir in cmd and ls in PowerShell list the contents of a directory, and dir /a in cmd includes hidden files.
11. pwd and cd
pwd stands for "print working directory," and it shows the full path of the directory you're in:
pwd
# /home/daniel/projects/myappcd changes the current directory:
cd projects/myapp # Goes into a directory
cd .. # Goes up one level
cd ~ # Goes to your home directoryIn PowerShell, pwd works too. In cmd, cd without arguments prints the current directory, while on macOS and Linux, it takes you to your home directory.
12. cp, copy
The cp command copies a file:
cp old_file.txt copy_of_old_file.txtTo copy a directory with everything in it, add the -r (recursive) flag:
cp -r originaldirectory/ newdirectoryIn cmd, use copy for files and xcopy or robocopy for directories:
copy old_file.txt copy_of_old_file.txt13. cat, type
To print the contents of a text file in the terminal without opening an editor, use cat on macOS and Linux, or type in cmd. PowerShell accepts both:
cat requirements.txt
# certifi==2026.11.20
# charset-normalizer==3.5.3
# idna==3.20
# requests==2.34.2
# urllib3==2.8.0For long files, less lets you scroll through the file. Press q to quit.
14. mv, move
The mv command moves files and directories, or renames them:
mv source_file.txt renamed_file.txt # Renames a file
mv renamed_file.txt newdir/ # Moves it to another directoryYou can also use wildcards. For example, this moves all .py files in the current directory into another one:
mv *.py mypythondir/In cmd, the equivalent is move:
move source_file.txt renamed_file.txt15. rm, del
The rm command deletes files:
rm file_to_remove.txtTo delete a directory and everything in it, add the -r (recursive) flag. Adding -f (force) also skips confirmation prompts and errors for missing files:
rm -r dir_to_remove/
rm -rf dir_to_remove/To delete an empty directory, use rmdir dir_to_remove.
In cmd, use del to delete files and rmdir /s to delete a directory with its contents:
del file_to_remove.txt
rmdir /s dir_to_removeThe command line has no trash can. Files you delete with these commands are gone, so double-check the path before you press Enter, especially with rm -rf.
16. exit
When you're done, close your shell session with:
exitThis works in Bash, zsh, PowerShell, and cmd, and usually also closes the terminal window or tab.
Command-line editors#
Once you're comfortable in the terminal, switching to another window just to edit a file can feel slow. A command-line editor lets you edit code without leaving the terminal, which is especially useful on a remote server, where it may be your only option.
17. Vim and Neovim
Vim and its modern fork, Neovim, are keyboard-driven text editors that run in the terminal. Vim, or its predecessor vi, comes with macOS and most Linux distributions, so it's the editor you're most likely to find on a server. On Windows, download it from the Vim website.
To open a file in Vim, run:
vim myscript.pyVim has modes: you start in normal mode, where keys run commands. Press i to start typing (insert mode) and Esc to go back to normal mode.

Vim has a steep learning curve, but once you learn its keyboard shortcuts, it's one of the fastest ways to edit text. Run vimtutor for a built-in, 30-minute tutorial.
To quit Vim, press Esc, then type :q and press Enter. Use :wq to save and quit, or :q! to quit without saving.
18. Nano
Nano is a simple command-line text editor that's great for quick edits. It shows its keyboard shortcuts at the bottom of the screen, so you don't need to memorize anything:
nano myscript.pyPress Ctrl + O to save and Ctrl + X to exit. Nano comes with many Linux distributions. If the command isn't found, install it with your package manager, for example, sudo apt install nano.
19. Emacs
Emacs is one of the most extensible and customizable text editors available. Its community maintains extensive support for Python programming, with packages that add code completion, linting, and more.
Emacs runs on almost every OS. If you don't have it, see the download instructions, or install it with your package manager, for example, brew install emacs. To open it inside the terminal instead of in its own window, use the -nw (no window) flag:
emacs -nw myscript.pyDevelopment tools#
Python development involves more than writing code. You'll also work with virtual environments, version control, containers, and tools to test and debug your apps.
20. venv and virtualenv
Virtual environments are essential in Python development. Each one is a folder, usually named .venv, with its own Python interpreter and packages, so each project can use its own package versions without affecting others.
Python includes the venv module to create one:
python3 -m venv .venvvirtualenv is a separate tool that does the same job, faster and with more options. Install it with pipx, then create an environment:
pipx install virtualenv
virtualenv .venvNext, activate the environment, so python and pip use it. On macOS and Linux:
source .venv/bin/activateOn Windows, in PowerShell:
.venv\Scripts\Activate.ps1In cmd:
.venv\Scripts\activate.batIf PowerShell blocks the script, allow local scripts for your user with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned, then try again.
While an environment is active, your prompt starts with its name, such as (.venv), and pip install installs packages into it. To leave the environment, run deactivate. If you use uv, uv run uses the project's environment automatically, so you don't need to activate it.
21. git
Version control is one of the most important practices in software development. It keeps track of every change to your code, lets you go back to earlier versions, and makes it possible to work with other developers.
Git is by far the most used version control system. Install it from its download page, then see the available commands with:
git helpTo create a repository, use git init followed by a directory name:
git init my_repository
# Initialized empty Git repository in /home/daniel/my_repository/.git/This creates a local repository. To store your code online and collaborate with others, use a platform like GitHub, GitLab, or Bitbucket.
To copy a remote repository to your computer, use git clone with the repository's URL. This example clones a repository over SSH:
git clone [email protected]:username/repository.gitAdd a .gitignore file with .venv/ and __pycache__/ to every Python project, so your virtual environment and compiled files stay out of the repository.
22. docker
Docker packages your Python app with its Python version and dependencies into a portable container image, so it runs the same way on every computer and server. To get started, install Docker by following the Get Docker page for your OS.
To see the available Docker commands, run:
docker helpTo run a Python container and open its interactive shell, for example:
docker run -it --rm python:3.15To run an app with several services, such as a web app and a database, use Docker Compose. See the Docker Compose quickstart for an example with a Python app.
23. grep
grep searches text for a pattern. It's useful for finding where a function or setting appears in your code, or filtering long output.
For example, this counts the lines that contain "python" in a file, ignoring case (-i):
grep -ic python pythondocument.txt
# 2Note that -c counts matching lines, not matches. If a line contains "python" three times, it counts once. To count every match, use grep -io python pythondocument.txt | wc -l.
To search every file in a directory, add -r, as in grep -rn "def main" ., which also shows the line numbers (-n).
On Windows, PowerShell's Select-String does a similar job. It's case-insensitive by default:
Select-String -Pattern python -Path pythondocument.txt24. http (HTTPie)
HTTPie is a command-line HTTP client that makes it easy to send requests to web services. You can use it to test your Python APIs or call third-party APIs. Since it's a command-line tool, install it with pipx:
pipx install httpieHere's how to send a request to the GitHub API:
http GET https://api.github.com/users/octocatHTTPie prints the response headers and the JSON body, formatted and colored:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
...
{
"login": "octocat",
"id": 583231,
...
}25. ping
ping is available on virtually every OS. It sends small packets to a host and measures how long each reply takes, in milliseconds. You can use it to check whether you can reach a server, such as the one running your Python app:
ping -c 4 sevalla.comThe -c 4 flag sends four packets and stops. Without it, ping keeps running on macOS and Linux until you press Ctrl + C. On Windows, ping sends four packets by default.
Some servers and firewalls block ping, so no reply doesn't always mean a server is down. To check a web app, request it with curl -I https://example.com or HTTPie instead.
26. kill
Sometimes a program, such as a development server, keeps running in the background, or stops responding. The kill command stops a process by its process ID (PID).
To find the PID, search the running processes by name:
pgrep -f http.server
# 4690Then stop the process:
kill 4690If it doesn't stop, kill -9 4690 forces it to quit. If a port is already in use, for example, port 8000, lsof -i :8000 shows the process that's using it on macOS and Linux.
On Windows, find the PID with tasklist or netstat -ano, then stop the process with taskkill /PID 4690 /F.
Command reference table#
Here's a quick reference for every command in this article:
| Command | Usage |
|---|---|
py install | Installs Python versions on Windows |
brew, pyenv | Installs Python and switches between versions on macOS |
apt, dnf, pacman | Installs packages on Linux distributions |
python, python3 | Runs the Python interpreter |
pip | Installs Python packages |
pipx | Installs Python command-line tools |
uv | Manages Python versions, projects, and dependencies |
sudo | Runs a command as an administrator |
chmod | Changes file permissions |
ls, dir | Lists the contents of a directory |
pwd, cd | Shows and changes the current directory |
cp, copy | Copies files and directories |
cat, type | Prints file contents |
mv, move | Moves or renames files and directories |
rm, del | Deletes files and directories |
exit | Closes the current shell session |
vim, nvim | Keyboard-driven text editor |
nano | Simple text editor for quick edits |
emacs | Highly customizable text editor |
venv, virtualenv | Create virtual environments |
git | Version control |
docker | Builds and runs containers |
grep | Searches text for patterns |
http | Sends HTTP requests |
ping | Tests network connectivity |
kill | Stops a process |
Summary#
Python is one of the easiest programming languages to learn, and the command line is often the one part that holds beginners back. In this article, you learned what the CLI is and the commands you'll use most as a Python developer: installing Python, managing packages and virtual environments, working with files, editing code in the terminal, and using tools like Git, Docker, and HTTPie.
When your Python app is ready to go live, you can deploy it from Git with Sevalla's Application Hosting. Sevalla detects Python projects, installs your dependencies with pip, uv, Poetry, and other package managers, and runs your web server, background workers, and migrations. See the guides to deploying Python applications for Django, FastAPI, Flask, and more.