Multiple Python versions on MacOS

# Install homebrew

Homebrew is a package manager for MacOS, must have CLI utility.


$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


# Install latest python

MacOS comes with a python version but you should install the latest stable version of python.


$ brew install python


# Install pip

First of all download the get-pip file


$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Now run this file to install pip

$ python get-pip.py


# Change global default python to latest python

$ sudo ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python


# Install pyenv

pyenv makes it easy to install, manage, and switch between multiple Pythons versions.


$ brew install pyenv


# Install multiple python versions in pyenv

$ pyenv install 3.9.4

$ pyenv install 2.7.16


# Change default python in pyenv to latest and greatest

$ pyenv global 3.9.4


# Running pyenv

$ pyenv versions


$ python -m venv venv

$ source ./venv/bin/activate

(venv) $ which python

/Users/mbbroberg/Develop/my_project/venv/bin/python


To exit the virtual environment

$ deactivate


Reference: 

https://opensource.com/article/19/6/python-virtual-environments-mac

https://jacobian.org/2019/nov/11/python-environment-2020/


Popular posts from this blog

Installing Python Boto3 for AWS on MacOS

Installing CloudCustodian for AWS