Install mulitple versions of Python 3 on MacOS [duplicate]
Asked Answered
B

2

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.

Branscum answered 11/1, 2019 at 12:45 Comment(3)
github.com/pyenv/pyenv#homebrew-on-macosRevelation
From my experience, best is to use the official .pkg installers from Python website. Multiple versions are installed to /Library/Frameworks/Python (or similar), the only thing is adjusting the PATH in .bash_profile to use them.Canaster
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.Brickwork
B
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.

Brickwork answered 11/1, 2019 at 21:8 Comment(0)
A
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  
Apocrine answered 11/1, 2019 at 21:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.