I want to have multiple versions of Python 3 on MacOS. For example I need Python3.6 and Python3.7. When using Linux I would simply create an alt install by building Python from source, as follows:
I will then have a new version of Python installed in usr/local/lib/pythonx.x
.
That works perfectly on Linux. How would I go about having access to multiple versions of Python 3 on MacOS?
EDIT: Just to clarify my use case a bit more. I use multiple versions on Python installed on the OS so that I can then use Pipenv for different projects specifying different Python versions.
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 e.g. tensorflow isn't compat. with 3.7 :-(
You can set a 'default' version everywhere else:
$ pyenv global 3.7.2
It plays well with pipenv
too.