On Linux and macOS, python and python3 are two separate commands: python3 runs Python 3, while python is optional and may point to Python 3, point to an old Python 2, or not exist. Run python --version and python3 --version to see what each one does on your machine.
The short version: when you want Python 3 and the machine is not yours, type python3. When a virtual environment is active, either command works. On Windows the answer is different, and it is covered below.
How to check what each command runs
python --version
python3 --version
Example output on a machine where both exist (your version numbers will differ):
Python 3.12.3
Python 3.12.3
If python is missing you will see a shell error such as python: command not found (bash) or zsh: command not found: python. That does not mean Python is broken. It means no command with that name exists on your PATH. To see where each command lives:
which python
which python3
On Windows in PowerShell, use Get-Command python and Get-Command python3 instead.
Why there are two names
Python 2 and Python 3 were incompatible, and for years both had to be installed side by side. The convention that grew up was one command per major version: python2 for Python 2 and python3 for Python 3. The plain python name was left ambiguous.
That convention is written down in PEP 394, an informational PEP that is still marked Active. It tells distributors (Linux distributions and similar) to provide python3 whenever a Python 3 interpreter is installed, and each command should run a version of its own major release. It then says the python command is optional. If it exists, it is expected to invoke either the same version as python3 or the same version as python2. The PEP does not require python to be Python 3.
So different systems legitimately behave differently. The PEP notes that some newer Linux distributions provide a python command that refers to Python 3, while others provide none. Distributors may also let an administrator configure it. This is why a tutorial that says "run python" works on one machine and fails on the next.
What each command means on each system
| System | python3 | python |
|---|---|---|
| Linux or macOS, no virtual environment | Python 3, provided when a Python 3 interpreter is installed | Optional. Python 3, Python 2, or missing, depending on the distributor and administrator |
| Any Unix with a virtual environment active | Available, same version as the environment | Always available, and refers to the environment's interpreter |
| Windows | Mimics python; documented as not meant to be widely used | The recommended command; launches the requested version, an active virtual environment, or the default install |
Inside a virtual environment, the difference disappears
PEP 394 says that when a virtual environment is active, python should refer to that environment's interpreter and should always be available. The matching python3 should be there too. That makes a virtual environment the most predictable way to work: the same command works on every machine, and you never touch the system Python. The PEP recommends virtual environments for software that did not ship with the system.
python3 -m venv .venv
source .venv/bin/activate
python --version
Use python3 for the first line, because outside the environment python may not exist. After activation, python is guaranteed. The full steps, including Windows activation, are in Python virtual environments (venv).
Python vs python3 on Windows
Windows has no Python 2 history to manage, and the documentation treats the two commands differently from Unix. According to the Python documentation for Windows, the recommended command for launching Python is python. It launches the version requested by the script, an active virtual environment, or the default installed version, which is the latest stable release unless configured otherwise.
The python3 command also exists. The documentation says it mimics python and is intended to catch accidental uses of the typical POSIX command on Windows, but is not meant to be widely used or recommended. So typing python3 on Windows is harmless, but there is no reason to prefer it.
When you have several runtimes installed, the documented recommendation is the py command. It matches python by default, accepts options to select a specific version, and has subcommands to manage installations. To see what is installed:
py list
To launch a specific runtime, pass its tag, for example py -V:3.15, which is the form the documentation shows.
If python or python3 opens the Microsoft Store
On Windows 10 and 11, a command that opens the Store instead of running Python usually means an app execution alias is answering before a real install is found. The Python documentation says to open "Manage app execution aliases" from the Start menu and check that the aliases for "Python (default)" are enabled. Our guide on app execution aliases and Python on Windows walks through the settings, and installing Python on Windows covers the install itself.
Which one to write in a script
For a script that runs on Unix systems you do not control, use a shebang that names the major version:
#!/usr/bin/env python3
The Python documentation for Unix recommends this form as usually a good choice, since env searches the whole PATH. Some systems may lack env, in which case you would hardcode /usr/bin/python3. PEP 394 gives script publishers the same advice: prefer specific shebangs such as python3 when targeting several environments. Use #!/usr/bin/env python only for scripts that are meant to run inside an active virtual environment, where python is guaranteed.
If your script needs to start another Python process, the PEP advises querying sys.executable rather than guessing a command name. That way the child process uses the same interpreter as the parent:
import subprocess
import sys
subprocess.run([sys.executable, "other_script.py"], check=True)
Installing from source: do not overwrite python3
If you build Python from source on Linux, the Unix documentation warns that make install can overwrite or masquerade the python3 binary. It recommends make altinstall, which installs only the versioned binary such as python3.12. This matters because system tools often depend on the distribution's own python3. Replacing it can break them.
If it still fails
If python3 reports command not found, no Python 3 is installed or it is not on your PATH: install it with your system's package manager or from python.org. If python --version prints Python 2 on an old system, do not change what python points to. System tools may depend on it. Use python3 or a virtual environment instead. If the version printed is not the one you expected, run which -a python3 on Linux and macOS (or where.exe python on Windows) to list every match on your PATH in order. The first one wins.
Frequently asked questions
- Is python the same as python3?
- Not necessarily. On Linux and macOS they are two separate commands. PEP 394 says that if python exists it should match either python3 or python2, but it does not require it to be Python 3, and some systems have no python command at all. Run python --version and python3 --version to see what yours does.
- Should I use python or python3 in a script's shebang?
- Use #!/usr/bin/env python3 when the script must run on Unix systems you do not control. The Python documentation recommends that form, and PEP 394 advises script publishers to prefer specific shebangs like python3. Use #!/usr/bin/env python only for scripts meant to run inside an active virtual environment.
- Why does python3 work on my Mac or Linux machine but python says command not found?
- The distributor chose not to provide a python command. PEP 394 makes python optional, so a system can ship python3 only. Use python3 directly, or activate a virtual environment, where python is always available.
- Is there a difference between python and python3 on Windows?
- The Python documentation says python3 on Windows mimics python and is meant to catch accidental uses of the POSIX command, not to be widely used. For several installed versions, the documented command is py.