5

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:

  1. Download the source tarball for a specific Python version and extract
  2. ./configure
  3. sudo make
  4. sudo make altinstall

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.

Asclepius
  • 57,944
  • 17
  • 167
  • 143
darkpool
  • 13,822
  • 16
  • 54
  • 89
  • https://github.com/pyenv/pyenv#homebrew-on-macos – Paolo Jan 11 '19 at 12:50
  • From my experience, best is to use the [official `.pkg` installers from Python website](https://www.python.org/downloads/mac-osx/). Multiple versions are installed to `/Library/Frameworks/Python` (or similar), the only thing is adjusting the `PATH` in `.bash_profile` to use them. – hoefling Jan 11 '19 at 21:09
  • The question was asked before, but doesn't have an **accepted** answer. This one does. So if anything, _it_ should be marked as duplicate, since it's less helpful. – Dogweather Jan 13 '19 at 05:30

2 Answers2

9

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.

Dogweather
  • 15,512
  • 17
  • 62
  • 81
0

Install binaries:

Go to https://www.python.org/downloads/mac-osx/, download the 32/64bit installer and follow the install instructions.

Install from source:

curl -OL http://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz  
tar xzvf Python-3.7.2.tgz  
cd Python-3.7.2  
./configure --prefix=/usr/local --enable-shared
make  
make install  
Quentin
  • 100
  • 6