Installing Python 3 in Mac OS
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.
- run
python --versionand you’ll find that it is some version ofpython 2.7then runpip -versionand you’ll find that it is some version ofpython 2.7 pip. Unless you are on Mac OS 10.15 Catalina, which does without any default scripting languages. - 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)" - run
brew install python3 - run
brew postinstall python3in order to installpip3the latest package manager - Lets make sure that when you run the
pythoncommand or thepipcommand, your Mac usespython3andpip3respectively. All we have to do is add the followingsymlinksto your.bash_profile - Using
vimor your favorite editing tool, open your.bash_profileand add the following to the beginning of yourPATH
export PATH=/usr/local/opt/python/libexec/bin:$PATH - run
python -m pip install --upgrade setuptools - For the time being, I do not recommend running the following command
python -m pip install --upgrade pipas there is a known issue preventingpip3from 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. - As a bonus step, my favorite way to work with virtual environments is simple.
python -m venv dirnamethensource dirname/bin/activateto activate the virtual environment, and of coursedeactivateto deactivate it. In there, you can have isolated environments where you can installpippackages 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.








