pip: command not found and python: command not found
This error occurs when Python binaries are missing from the system PATH. Use python -m pip or add the Python installation directory to PATH.
Root Cause Analysis
This error occurs when Python tries to execute system CLI commands like pip or python in a subprocess or shell, but the executable binary is not found in the operating system's PATH environment variable.
Cause 1: Python Not Added to System PATH During Installation
On Windows, the official installer includes an unchecked checkbox 'Add python.exe to PATH' by default. If unchecked, the shell cannot resolve python or pip commands from terminal prompts.
Cause 2: python3 vs python Command Name Mismatch on macOS and Linux
Modern Linux distributions and macOS ship with python3 and pip3 installed, but do not create unversioned python aliases by default to avoid breaking system tools.
Cause 3: Inactive Virtual Environments
When a project virtual environment is not activated, tools installed exclusively inside .venv/bin or .venv/Scripts are unavailable to the global shell.
Reproduction Code (MCVE)
import subprocess
# Executing a non-existent binary in subprocess triggers FileNotFoundError
subprocess.run(['non_existent_pip_binary_xyz', '--version'], check=True)
Solution 1: Invoke pip via sys.executable (python -m pip)
Always call python -m pip or python3 -m pip. This bypasses shell PATH ambiguity by directing the active Python executable to launch its associated pip module.
import sys
import subprocess
# Execute pip via the current Python executable
result = subprocess.run([sys.executable, '-m', 'pip', '--version'], capture_output=True, text=True)
print(f'Pip verified: {result.stdout.strip()}')
Solution 2: Configure System PATH Environment Variables
Add the Python installation directory and its Scripts/ (or bin/) folder to your OS environment variables.
import sys
from pathlib import Path
python_dir = Path(sys.executable).parent
scripts_dir = python_dir / 'Scripts'
print(f'Python Directory: {python_dir}')
print(f'Scripts Directory: {scripts_dir}')
Common Mistakes & Edge Cases
1. Windows py Launcher
On Windows, the py launcher is always added to PATH even if Python isn't. Running py -m pip install <package> works reliably across all installed Python versions.
2. Restarting Terminals After PATH Changes
After modifying environment variables in Windows System Properties or ~/.bashrc/~/.zshrc, you must restart active terminal windows for changes to take effect.
3. Contrasting FileNotFoundError vs PermissionError
FileNotFoundError: The executable cannot be found in any directory listed in PATH.PermissionError: The file was found, but lacks execute (+x) permissions.
4. Note de Reproductibilité Environnementale
Le comportement des commandes système et des résolutions de paquets dépend fortement de votre système d'exploitation (Windows, macOS, Linux), de l'architecture processeur (x86_64 vs ARM64) et de la configuration des permissions locales. Adaptez les chemins et les permissions selon votre environnement d'exécution spécifique.