Adding Python to the system PATH is an important step to ensure you can run Python from the command line, regardless of your current directory.
On macOS, Python installed via the official installer from Python.org, Homebrew, or Anaconda is usually already added to the PATH. If not, you can manually add it:
Step 1: Find Python’s install path
- If you install from Python.org, it’s typically /Library/Frameworks/Python.framework/Versions/3.x/bin (replace 3.x with your Python version).
- If installed via Homebrew, it’s /usr/local/bin.
Step 2: Edit ~/.bash_profile or ~/.zshrc
- Open Terminal.
- Determine which shell you are using: echo $SHELL.
- If you are using Bash (default on macOS versions before Catalina), edit ~/.bash_profile:
open -e ~/.bash_profile
- If you are using Zsh (default on macOS Catalina and later), edit ~/.zshrc
- Add the following line (replace <path-to-python> with the actual path):
export PATH="<path-to-python>:$PATH"
Step 3: Apply the changes
For changes to take effect, either restart the Terminal or source the profile:
- Bash: source ~/.bash_profile
- Zsh: source ~/.zshrc
That’s all!