Sitemap
Yousef

Yousef

Principal Software Engineer and P90X enthusiast from San Francisco, CA

Installing Python 3 in Mac OS

3 min readOct 30, 2019
Press enter or click to view image in full size

We have all been there. Believe me, I get it. I understand you, and I’m with you. I’ll stay with you every step of the way, and we will get through it together.

  1. run python --version and you’ll find that it is some version of python 2.7 then run pip -version and you’ll find that it is some version of python 2.7 pip. Unless you are on Mac OS 10.15 Catalina, which does without any default scripting languages.
  2. Install the best package manager for Mac OS, Homebrew. I like it for many reasons, but the key reasons are that it doesn’t clutter your machine, it keeps all your installations in one directory, brew cask manages your GUI app installs, brew doctor helps ensure your machine has the right permissions, and it is easy to uninstall packages and clean up.
    run /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  3. run brew install python3
  4. run brew postinstall python3 in order to install pip3 the latest package manager
  5. Lets make sure that when you run the python command or the pip command, your Mac uses python3 and pip3 respectively. All we have to do is add the following symlinks to your .bash_profile
  6. Using vim or your favorite editing tool, open your .bash_profile and add the following to the beginning of your PATH
    export PATH=/usr/local/opt/python/libexec/bin:$PATH
  7. run python -m pip install --upgrade setuptools
  8. For the time being, I do not recommend running the following command python -m pip install --upgrade pip as there is a known issue preventing pip3 from working properly when you do so. Some information about that can be found in issue 43867 and here. Sorry about that. I will update this article as soon as this issue is resolved. If you’ve found a solution, feel free to leave notes in the comments section.
  9. As a bonus step, my favorite way to work with virtual environments is simple. python -m venv dirname then source dirname/bin/activate to activate the virtual environment, and of course deactivate to deactivate it. In there, you can have isolated environments where you can install pip packages without affecting other projects. Say, if one projects requires one version of a package, and another project requires a different version of the same package, virtual environments help you have multiple isolated python environments. I’ll write a story about that at a later time. In the mean time, you can read more here.

That’s it, if you now run python --version and pip --version respectively in a new bash window you’ll see that they are now pointing at the python3 versions.

Get Yousef’s stories in your inbox

Join Medium for free to get updates from this writer.

I will be updating this article in the near future with more details as to the whys of some of these steps, but if you’re looking for a quick way to get going, while being able to easily uninstall things and cleanup your machine without causing a mess, and keeping things under your control, these are the best steps I’ve discovered to date. Happy snaking.

--

--

Yousef
Yousef

Written by Yousef

Principal Software Engineer and P90X enthusiast from San Francisco, CA