Skip to content

Instantly share code, notes, and snippets.

@chriswayg
Last active August 28, 2021 07:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswayg/2c46a6fbbe1cbdd2ee7167a5cbf4b2a2 to your computer and use it in GitHub Desktop.
Save chriswayg/2c46a6fbbe1cbdd2ee7167a5cbf4b2a2 to your computer and use it in GitHub Desktop.
Install Python on macOS in 30 seconds - Oneliner that downloads, installs and activates Python 2.7 or 3.x from Python.org

Install Python on macOS in 30 seconds

Install Python on OS X / macOS 10.9 - 10.15+ (64 bit)

  • Catalina, Mojave, High Sierra, Sierra, El Capitan, Yosemite or Mavericks
  • Usage: copy one of the three following lines and paste it into your terminal. Type the sudo password.
Python 3.8
sudo true; v=3.8.4; f=python-${v}-macosx10.9.pkg; cd $TMPDIR; { curl -LfOsS https://www.python.org/ftp/python/${v}/$f ; cd ~-; } && sudo installer -pkg $TMPDIR/$f -target / &&  v=$(echo "$v"|cut -d'.' -f1-2); "/Applications/Python ${v}/Update Shell Profile.command" && . ~/.bash_profile
Python 2.7
sudo true; v=2.7.18; f=python-${v}-macosx10.9.pkg; cd $TMPDIR; { curl -LfOsS https://www.python.org/ftp/python/${v}/$f ; cd ~-; } && sudo installer -pkg $TMPDIR/$f -target / &&  v=$(echo "$v"|cut -d'.' -f1-2); "/Applications/Python ${v}/Update Shell Profile.command" && . ~/.bash_profile
Python x.y.z (input the version)
  • Among the current choices: 2.7.18 and 3.6.8 3.7.8 3.8.4
sudo true; read -p 'Version? ' v; f=python-${v}-macosx10.9.pkg; cd $TMPDIR; { curl -LfOsS https://www.python.org/ftp/python/${v}/$f; cd ~-; } && sudo installer -pkg $TMPDIR/$f -target / &&  v=$(echo "$v"|cut -d'.' -f1-2) && "/Applications/Python ${v}/Update Shell Profile.command" && . ~/.bash_profile

Create a virtual environment

mkdir ~/PyProject1 && cd ~/PyProject1 && pip3 install --upgrade pip && pip3 install pipenv==2020.5.28 && pipenv install && pipenv shell

env | grep -i pip
python3

Remove ALL python versions from Python.org

sudo rm -rf /Library/Frameworks/Python.framework/Versions/?.*; sudo rm -rf "/Applications/Python "?.?; cd /usr/local/bin &&  { ls -l | grep '/Library/Frameworks/Python.framework/Versions/*' | awk '{print $9}' | tr -d @ | xargs sudo rm -rfv; cd ~-; }; b="$HOME/.bash_profile"; sed -i.bak '/Frameworks\/Python*/d' $b; sed -i '' '/PATH for Python/d' $b; sed -i '' '/bash_profile\.pysave/d' $b && nano ~/.bash_profile
  • check with nano ~/.bash_profile and clean up any remaining lines from Python.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment