Installing Python 3 Mac OS X can be tricky as Python 2 is already pre-installed in Mac OS X. It is a good idea not to do a direct install of Python 3 or an in-place upgrade from 2 to 3 on Mac OS X, rather it is better to use BREW to install Python 3. Brew is a package manager for Mac OS X.
We will be installing Python 3 using Brew.
What is Brew/HomeBrew?
Brew or HomeBrew is a package manager for Mac OS X. It is a simple command line tool to install any package that you might need. The prerequisite to install Brew is XCode.
How to Install Brew?
Just copy paste the following code in a Terminal Window and follow the steps, you will have brew installed.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once you have Brew installed, paste the following commands one after the other in the Terminal Window.
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile source~/.bash_profile
The first command ensures that the OS searches /usr/local/bin before any other directory. This should complete the setup for Brew.
How to Install Python 3?
Once Brew is installed type the following in the Terminal Window to install Python 3.
brew install python3
The following command should tell you where Python3 has been installed and if it worked you should see something like this.
which python3
/usr/bin/python/
This should complete the Python3 installation but we are not done yet. We need to setup virtual environments that will help us in creating a segregated dev environment for you to play around. It is like a sandboxed environment where you can write your code.
Install Virtual Environment
To install virtual environment, you need to have pip3 which is a part of Python 3.x installation. Run the following command to install virtual environment.
pip3 install virtualenv
Once virtual environment is installed we need to create a virtual environment, for that follow these steps.
mkdir pytut
cd pytut
virtualenv -p python3 dev
source ./dev/bin/activate
deactivate
This creates a directory called dev with some libraries and it can be activated by using the activate command. To deactivate the environment just type deactivate.
Now watch this video for the step by step tutorial.
Do let me know if you have any questions by commenting below and I will be more than happy to answer them.