Is using pyenv the best python version management for Mac?
macos - How can I install multiple versions of Python on latest OS X and use them in parallel? - Stack Overflow
Recommended way to manage several installed versions of Python (macOS)
What are your preferred method(s) for installing multiple python versions on macOS?
Is it better to use pyenv or brew to manage multiple versions of python on a Mac?
pyenv is the thing you want. It works very very well:
pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build, and modified for Python.
https://github.com/pyenv/pyenv
Install it via Homebrew:
$ brew update
$ brew install pyenv
It handles the download, compilation, and installation of various pythons for you, e.g.:
$ pyenv install 3.7.2
It can show you which versions you've installed, and which is active:
$ pyenv versions
system
3.6.7
* 3.7.2
When you're in a new project directory, just tell pyenv which python version to use there:
$ pyenv local 3.6.7 # Because tensorflow isn't compat. with 3.7 :-(
You can set a 'default' version everywhere else:
$ pyenv global 3.7.2
UPDATE, AUG 2024: I've gradually switched over to asdf because I work with a lot of different languages. The asdf project also publishes new version recipes very quickly. The asdf CLI interface is a little clunkier (verbose) because it can handle all languages. But pyenv never let me down for all the years I used it. If I was only doing Python development I might still be using it.
brew alone has been sufficient for me to use multiple versions of Python. I haven't needed pyenv or conda for it.
To install various versions using brew, run commands such as:
brew install [email protected]
brew install [email protected]
When creating a virtual environment, create it using one of:
/usr/local/opt/[email protected]/bin
/usr/local/opt/[email protected]/bin
Please list the bin directory above using ls in order to find and use the python executable in it.
For macOS M1 (not Intel) (see also, M1 brew setup), modify brew install path, eg:
/opt/homebrew/Cellar/[email protected]/bin
Please list the bin directory above using ls in order to find and use the python executable in it.
Lastly, the version of /usr/local/bin/python3 is probably not the version you want for your virtual environment.
When I use VS Code and select a version of Python on macOS, I have the following versions:
-
Python 3.12.8 ('3.12.8') ~/.pyenv/versions/3.12.8/bin/python
-
Python 3.13.2 /opt/homebrew/bin/python
-
Python 3.12.8 /usr/local/bin/python3
-
Python 3.9.6 /Library/Developer/CommandLineTools/usr/bin/python3
-
Python 3.9.6 /usr/bin/python3
I believe having this many versions of Python in different locations messes me up when trying to install packages (i.e. using brew vs pip3 vs pyenv), so I'm wondering what the best way is to clean this up and make package + version management easier?