Installing Python3.6 alongside Python3.7 on Mac
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Installing Python 3.6 Alongside Python 3.7 on Mac
Installing multiple versions of Python on a Mac can be quite handy, especially when projects depend on specific versions. In this article, we will guide you through installing Python 3.6 alongside Python 3.7, ensuring both environments are accessible.
Prerequisites
Before proceeding with the installation, ensure you have the following:
- Homebrew: A package manager for macOS that simplifies the installation of software.
- Command Line Tools for Xcode: Required by Homebrew. Install them with the command:
Step-by-Step Installation
1. Installing Homebrew
If Homebrew is not already installed, execute the following command in your Terminal:
To ensure Homebrew is set up properly, run:
2. Installing Python 3.6
Homebrew might not have Python 3.6 directly, as it generally supports the most recent versions. Luckily, you can access older Python versions via Homebrew's formulae archive.
- Add the Homebrew-archive tap:
- Install Python 3.6:
After installation, to ensure the correct version of Python 3.6 is called, use the complete path that Homebrew provides, usually found via:
3. Installing Python 3.7
Python 3.7 should be directly available from Homebrew:
Just as with Python 3.6, you can find and use the specific path for Python 3.7.
4. Managing Python Versions
To manage and switch between different Python versions easily, consider using pyenv, a tool specifically designed for this purpose.
- Install
pyenvvia Homebrew:
- Add
pyenvto your shell:
- Install the desired Python versions using
pyenv:
- Set the global version:
- To switch to a specific version for a project, navigate to the project directory and:
Additional Tips
- Virtual Environments: Always use virtual environments for project isolation. Python's
virtualenvor the built-invenvmodule can help manage dependencies project-wise without version conflicts. - Environment Variables: Be aware of the
PATHchanges and manage your shell configuration files (~/.bash_profile,~/.zshrc) to ensure the correct path priorities.
Summary Table
| Task | Command |
| Install Homebrew | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| Install Python 3.6 | brew install [email protected] |
| Install Python 3.7 | brew install [email protected] |
| Install pyenv | brew install pyenv |
| Install Python 3.6.8 via pyenv | pyenv install 3.6.8 |
| Install Python 3.7.9 via pyenv | pyenv install 3.7.9 |
| Set global Python version | pyenv global 3.7.9 |
| Set local Python version | pyenv local 3.6.8 |
Conclusion
By following the steps outlined above, you can successfully install and manage both Python 3.6 and Python 3.7 on your Mac. Using tools like pyenv simplifies this process significantly, helping you concentrate on coding rather than environment management. By leveraging virtual environments, your projects remain insulated from any systemic changes in Python versions or package updates.

