Skip to content

Instantly share code, notes, and snippets.

@aberezin
Last active May 16, 2022 15:21
Show Gist options
  • Save aberezin/e61a16262b720acde70717cc4372fa49 to your computer and use it in GitHub Desktop.
Save aberezin/e61a16262b720acde70717cc4372fa49 to your computer and use it in GitHub Desktop.

Installing python on MacOS The Right Way

To completely avoid the MacOS python, start with brew or macport. If you start with macports, you will not be using that python version for much (ideally). But we need some, somewhat isolated python to start with.

sudo port install python38
sudo port install py38-pip
sudo port select --set python python38
sudo port select --set pip pip38
sudo port select --set python3 python38

# One terrible feature of macport's version is that you can
# select and upgrade the python version and pip versions separately.
# This means you can be using the using .../bin/python38 but the pip is installing elsewhere

#alias pipx=/Users/aberezin/Library/Python/3.8/bin/pipx
sudo pip install virtualenv
sudo pip install virtualenvwrapper
#dont know why the wrapper is here but I symlink it to better place
mkdir -p ~/.local/bin
ln -s /opt/local/Library//Frameworks/Python.framework/Versions/3.8/bin/virtualenvwrapper.sh ~/.local/bin/virtualenvwrapper.sh
#I am also going to install virtualenv here
#But pipx should be used sparingly since it adds a layer of complexity
#I am only using it to exec virtualenv
pip install pipx
#now make it hard to use pip outside a virtualenv
export PIP_REQUIRE_VIRTUALENV=1
mkvirtualenv py38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment