Home/Blog/Python/How to Fix Python on macOS: Troubleshoot Path Issues and Upgrade Guide
Python

How to Fix Python on macOS: Troubleshoot Path Issues and Upgrade Guide

Resolve Python path conflicts, upgrade from Python 2 to 3, and fix pip issues on macOS. Complete troubleshooting guide with solutions.

How to Fix Python on macOS: Troubleshoot Path Issues and Upgrade Guide

This article will help you troubleshoot and solve some of the issues you might encounter as you start moving to Python 3.x on MacOS, including path conflicts, pip installation problems, and virtual environment setup.

Preventing Python Problems

Most issues you will encounter are related to where Python is installed vs what paths are in your system path variables vs where pip is installing your Python modules. You need to make sure all of these file system paths match up, otherwise you’ll encounter issues where you install a package with pip, but Python still complains that the package is missing.

Use Virtual Environments

The best way to prevent problems is to install virtualenv at the system level and use virtual environments for everything else. Virtual environments isolate your Python projects and prevent conflicts between different package versions.

Key Rule: Avoid using sudo when installing Python packages. When you install a package using sudo, you install as the root user, which can cause permission conflicts later.

Reinstalling Python

A lot of issues can be resolved by simply re-installing Python. This is easy to do if you used Homebrew. Here’s how to clean up and reinstall Python properly:

Uninstall Existing Python

brew uninstall python2 python3

Reinstall Python

brew install python3

After this is done, test again and see if you are still getting errors. If you continue having trouble, try removing python2 and python3 again and only installing python3.

Checking System and Python Paths

The system path variables tell your terminal which file system paths to look at when you run a command. If you have your Python folder as part of the path variable, then you will be able to run the Python command to execute your scripts.

Check Your System PATH

echo $PATH

You should see a bunch of folders listed. Most likely you will see the /usr/bin folder listed. This is where you would expect the Python binary files to be located.

Check Python Installation Paths

A shortcut to see all the different Python paths on your system is to run the following commands:

python -c "import sys; print(sys.path)"
python3 -c "import sys; print(sys.path)"

Find Which Python You’re Using

If you are not sure the path of the Python installation you are currently using, you can type:

which python
which python3
which pip
which pip3

Python Installation Paths

Understanding where Python is installed on MacOS helps you troubleshoot path-related issues more effectively.

Default MacOS Python Location

/usr/local/bin/python

Homebrew Python Locations

  • Python 3: /usr/local/Cellar/python/<Python Version>
  • Python 2: /usr/local/Cellar/python@2/<Python Version>

Adding to System Paths

If a path is incorrect, it can cause things to not work. There are two kinds of paths to look at: system paths (where the system looks to find executable files) and Python paths (where Python looks to find packages).

Modifying System Paths

Warning: Be very careful when modifying system paths in /etc/paths. Incorrect changes can break your entire system.

Adding Python Paths

To add a path to your Python 3 installation, start by finding your site-packages folder:

python3 -m site

Create a .pth file in your site-packages directory to add custom paths:

sudo vi /usr/local/lib/python3.7/site-packages/example.pth

Frequently Asked Questions

Find answers to common questions

macOS includes system Python (2.7 legacy, deprecated), Xcode Python (for Apple tools), and user-installed versions (Homebrew, python.org). Never use system Python—it's for macOS internals only, breaks with OS updates. Recommended: install Python via Homebrew (brew install python) or python.org installer. Check versions: python --version (often Python 2.7 system), python3 --version (user-installed Python 3.x). Multiple Python 3 versions normal: python3.9, python3.10, python3.11 can coexist. Best practice: use python3 explicitly, never python (avoids Python 2). Version management: pyenv lets you switch versions per-project (brew install pyenv, pyenv install 3.11). Where installed: system Python in /usr/bin/python, Homebrew in /opt/homebrew/bin/python3 (M1/M2) or /usr/local/bin/python3 (Intel). Virtual environments critical: python3 -m venv venv isolates dependencies per project. Modern workflow: Homebrew Python + pyenv + venv.

macOS Catalina+ removed /usr/bin/python symlink to force Python 3 adoption. Fix: use python3 instead of python, or create alias. Quick fix: add to ~/.zshrc: alias python=python3 (zsh default since Catalina). Permanent solution: install Python via Homebrew—brew install python creates both python3 and python. Check PATH: echo $PATH should show /opt/homebrew/bin (M1/M2) or /usr/local/bin (Intel) before /usr/bin. If python3 also missing: install Homebrew (/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"), then brew install python. Virtual environments: python3 -m venv venv creates isolated environment with python symlink. IDE configuration: VS Code Python extension auto-detects python3. Avoid: installing Python 2 (end-of-life, unsupported). Verify fix: which python3 shows Homebrew path (/opt/homebrew/bin/python3), python3 --version shows 3.11+.

Two causes: outdated Python.org installer missing certificates, or corporate firewall/proxy. Python.org installers pre-3.6: missing SSL certificates in /Applications/Python 3.x/Install Certificates.command. Fix method 1: run that command (double-click Install Certificates.command in Python folder). Fix method 2: reinstall Python via Homebrew (brew install python)—includes certificates automatically. Homebrew Python location: uses macOS system certificates (no manual install needed). Corporate network: SSL inspection breaks pip—export pip certificate: pip config set global.cert /path/to/cert.pem or use --trusted-host flag: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org package. Temporary workaround (not recommended): pip install --trusted-host pypi.python.org package. Verify fix: pip install requests should work without SSL error. Modern solution: use Homebrew Python (avoids certificate issues entirely), keep macOS updated (updates root certificates).

Depends on installation method. Homebrew Python: brew uninstall python, brew install python (safest, cleanest). Python.org installer: sudo rm -rf /Library/Frameworks/Python.framework /Applications/Python\ 3.*, edit ~/.zshrc to remove Python paths. System Python: DON'T TOUCH (breaks macOS). Multiple versions: pyenv uninstall 3.10.5 removes specific versions. Clean slate approach: 1) Uninstall Homebrew Python (brew uninstall python), 2) Remove python.org versions (sudo rm -rf /Library/Frameworks/Python.framework), 3) Clean PATH in ~/.zshrc, 4) Reinstall via Homebrew (brew install python). Verify removal: which python3 returns nothing or /usr/bin/python3 (Xcode stub). Full reinstall time: 10-15 minutes. Recommended: stick with Homebrew for easy management (brew upgrade python for updates). Nuclear option: remove all user-installed Pythons, use Homebrew exclusively going forward. Backup: export pip list before uninstalling to reinstall packages after.

pip installs for Python 2 (if present), pip3 installs for Python 3—but varies by installation method. Modern macOS: pip command often missing (Python 2 removed), pip3 is standard. Homebrew Python: creates both pip and pip3 pointing to same Python 3 (symlinked). Best practice: use python3 -m pip instead of pip/pip3 (guarantees correct Python version). Why python3 -m pip better: explicitly uses Python 3's pip, avoids PATH confusion, works in virtual environments. Multiple Python 3 versions: pip3 uses default, python3.11 -m pip uses specific version. Check which: which pip3 shows path (/opt/homebrew/bin/pip3 for Homebrew). Virtual environments: always use pip (not pip3) inside activated venv—automatically tied to venv's Python. System pip: /usr/bin/pip doesn't exist on modern macOS (good). Recommendation: always use python3 -m pip install package for clarity and safety—avoids all ambiguity.

Automate Your IT Operations

Leverage automation to improve efficiency, reduce errors, and free up your team for strategic work.