Installing Specific Versions of Python 3 on macOS Using Homebrew

Nov 27, 2025 · Programming · 7 views · 7.8

Keywords: macOS | Homebrew | Python Installation | Version Management | Dependency Handling

Abstract: This technical article provides a comprehensive guide to installing specific versions of Python 3, particularly Python 3.6.5, on macOS systems using the Homebrew package manager. The article examines the evolution of Python formulas in Homebrew and presents two primary installation methods: clean installation via specific commit URLs and version switching using brew switch. It also covers dependency management, version conflict resolution, and comparative analysis with alternative installation approaches.

Evolution of Python Formulas in Homebrew

Before delving into specific installation techniques, it is essential to understand the historical development of Python-related formulas in Homebrew. In earlier versions, Homebrew maintained separate formulas for different Python versions, with python designated for Python 2 and python3 for Python 3. Following the official end-of-life for Python 2, the Homebrew community streamlined the naming convention, and the python formula now exclusively installs the latest stable release of Python 3.

Core Installation Methods

Since Homebrew by default only provides the most recent release of major versions, installing specific minor versions (such as Python 3.6.5) requires specialized approaches. The following two methods have been proven effective:

Method 1: Installation via Specific Commit

Homebrew supports installing packages using formula URLs from specific commits in the GitHub repository. For Python 3.6.5, execute the following command sequence:

# Unlink current Python if another version is installed
brew unlink python

# Install specific Python 3.6.5 version
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

The key here is the use of the --ignore-dependencies parameter. Different Python versions may rely on varying versions of underlying libraries, and this parameter helps circumvent installation failures due to dependency conflicts. The commit hash f2a764ef944b1080be64bd88dca9a1d80130c558 in the URL corresponds to the specific version of the Python 3.6.5 formula in the Homebrew core repository.

Method 2: Switching Installed Versions

If the target version has previously been installed via Homebrew, a simpler switching method is available:

# Check installed Python versions
brew info python

# Switch to specific version (example: 3.6.5_1)
brew switch python 3.6.5_1

This approach is suitable when the target version was successfully installed earlier but is currently linked to another version. The brew info python command lists all Python versions installed via Homebrew along with their installation paths.

Technical Analysis

Dependency Management Strategy

Dependency management requires particular attention when installing older Python versions. Newer Python formulas might update dependency requirements, while older versions could depend on legacy library versions. Although using --ignore-dependencies bypasses dependency checks, it may introduce runtime compatibility issues. It is advisable to manually verify the compatibility of critical dependencies post-installation.

Version Conflict Resolution

Version management becomes crucial when multiple Python versions coexist in the system. Homebrew employs a symbolic linking mechanism to manage the currently active Python version. The brew unlink python command removes the current symbolic link, preparing the environment for a new installation. Upon completion, the new version automatically becomes the default.

Comparative Analysis with Alternative Methods

Comparison with pyenv

Although the Q&A indicates that pyenv is not the user's preferred solution, understanding its differences from the Homebrew approach remains valuable. pyenv is specifically designed for managing multiple Python versions, offering finer-grained version control capabilities, including directory-based version switching. In contrast, the Homebrew method is more suited for system-level version management.

Comparison with Direct Compilation

Another common installation method involves downloading and compiling source code directly from the Python official website. While this method offers flexibility, it requires manual handling of dependencies and environment configuration. For most users, the automated solution provided by Homebrew is more convenient and reliable.

Practical Recommendations

Version Selection Considerations

When selecting a specific version for installation, factors such as project compatibility requirements, library dependencies, and security updates should be considered. Although the Python 3.6 series has reached end-of-life, it may still be necessary for certain legacy projects.

Environment Isolation

For projects requiring multiple Python versions concurrently, it is recommended to combine with virtual environment tools (such as venv or virtualenv) to isolate dependencies across different projects. This approach prevents system-level version conflicts and enhances development efficiency.

Troubleshooting

Common Issue Resolution

Various issues may arise during installation, including permission errors, network connectivity problems, and dependency conflicts, each requiring targeted solutions based on specific circumstances. Keeping Homebrew and its core repository updated is an effective strategy to prevent many common problems.

Installation Verification

After installation, verify the results using the following commands:

python3 --version
which python3

This confirms whether the installed version is correct and whether the executable location meets expectations.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.