Quick summary
Summarize this blog with AI
PATH tells your shell where to find executable programs. Add the directory containing Python, not the path to the executable itself. First check whether an existing interpreter or the Windows Python command already works; many package-import problems do not require any PATH change.
Check what is running before changing anything
In Windows PowerShell, run Get-Command python, py -All. In macOS or Linux, run command -v python3 and type -a python3. A missing command is useful evidence. Then run this script with the interpreter you intend to use:
import os
import shutil
import sys
print("Running interpreter:", sys.executable)
print("PATH lookup for python:", shutil.which("python"))
print("PATH lookup for python3:", shutil.which("python3"))
print("PYTHONPATH:", os.environ.get("PYTHONPATH", "<not set>"))
The running interpreter and the interpreter found by a fresh shell lookup can differ. None means a name was not found through PATH. An unset PYTHONPATH is normal and must not cause this diagnostic to fail.
PATH is not PYTHONPATH
PYTHONPATH adds directories to Python's module search path; it does not make the python command discoverable. Setting it globally can affect several Python installations. Do not add a project's virtual-environment packages to global PYTHONPATH to compensate for running the wrong interpreter. See the Python environment-variable reference.
Windows: prefer installation diagnostics, then edit one user entry
With the current Python install manager, start with python and py and follow its troubleshooting guide if either resolves incorrectly. Legacy launchers and older standalone installers have different behavior; do not assume a hard-coded Python39 directory exists.
- Locate the intended interpreter using its installer information or
sys.executablefrom a working full-path invocation. - Open Edit environment variables for your account. Record the existing user PATH entries before editing them.
- If manual setup is actually required, add a separate entry for the verified directory containing
python.exe. Add its correspondingScriptsdirectory only if you need installed command-line scripts globally. - Preserve all unrelated entries and use trusted directories. Earlier matching entries can take precedence.
- Open a new terminal and repeat the lookup and
sys.executablechecks. To undo your change, remove only the entries you added and open another new terminal.
Do not reconstruct the entire PATH using setx PATH "%PATH%;...". Microsoft documents expansion and a 1,024-character assignment limit that can truncate data. See setx limitations. An environment editor lets you change an individual entry without this particular rewrite hazard.
macOS and Linux: try a temporary shell change first
Use the actual trusted directory reported by your installation method. The path below is an example, not a directory to create. The parentheses create a subshell, so its PATH change disappears when the block ends.
(
export PATH="/verified/python/bin:$PATH"
command -v python3
python3 -c "import sys; print(sys.executable)"
)
Do not use /usr/local/bin/python3 as a PATH entry: that is an executable path, while PATH entries are directories. If the temporary check succeeds and you need a persistent setting, edit the startup file for the shell and session type you actually use. Record the original file and add one clearly identified line. Avoid repeatedly appending duplicate entries to several startup files. Reopen the terminal and verify; removing that line reverses your change. Do not replace the operating system's Python.
Most projects should use their own interpreter
For a project, use .venv/bin/python on macOS/Linux or .venv\Scripts\python.exe on Windows, and call pip through it. Configure your editor to use that same interpreter. This avoids making every project depend on one global PATH choice. See the pip environment workflow.
Validation: the Python diagnostic and a reversible subshell PATH change were tested on macOS. Windows environment-editor and install-manager steps are documentation-based and were not executed on a Windows machine.