Install Python

This is a step-by-step guide to install Python on Mac

Pavan Kulkarni

3 minute read

Install Python on Mac system easily and quickly. This post will give a complete walk through of installing Python using brew and manual process.

Python is one of the most commonly and widely used programming languages used by Data Engineers and Data Scientists. Per Wikipedia, Python is defined as “Python is an interpreted high-level programming language for general-purpose programming. Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales.”

Mac OS X, High Sierra, comes with Python 2.7 pre-installed. Continue reading if you want to install the latest version of Python (currently 3.x).

Python Installation as per official document

Installing Python on Mac using brew is a simple process. You need to have brew installed on your system as a pre-requisite. You can install brew from here

```
brew update
brew install python
```

But for some reason I had issues running python and pip on my terminal. python and pip were still pointing to the older 2.7 version. So, I found an alternate method to install Python 3 on mad which would override the default Python 2.7.

Alternate Python 3 Installation.

The alternate way to install Python 3 was to install it using Anaconda, I found this useful as Anaconda as this package is shipped with a web based editor called Jupyter. The Jupyter notebook is easy to use for both beginners and experts.

  1. Download Ananconda 3 for Mac from here
  2. Install the Anaconda3-x.x.x-MacOSX-x86_64.pkg
  3. This will install the Anaconda-Navigator in list of /Application
  4. A new directory anaconda3 will be created at ~/$HOME/ location.
  5. Check you ~/.bash_profile for entry like.

    # added by Anaconda3 5.0.1 installer
    export PATH="/Users/pavanpkulkarni/anaconda3/bin:$PATH"
    

    If this is not in the ~/.bash_profile file, go ahead and add it. Run source ~/.bash_profile after you have made changes. This will make sure the latest changes are being reflected in you system.

  6. Open a new terminal and run the below command to verify python installation.

    Pavans-MacBook-Pro:~ pavanpkulkarni$ python
    Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct  6 2017, 12:04:38)
    [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1+3
    4
    >>>
    
  7. Check the installation paths

    Pavans-MacBook-Pro:~ pavanpkulkarni$ which pip
    /Users/pavanpkulkarni/anaconda3/bin/pip
    Pavans-MacBook-Pro:~ pavanpkulkarni$ which python
    /Users/pavanpkulkarni/anaconda3/bin/python
    
  8. Run jupyter notebook and start scripting

    Pavans-MacBook-Pro:~ pavanpkulkarni$ jupyter notebook
    [I 15:47:32.801 NotebookApp] JupyterLab alpha preview extension loaded from /Users/pavanpkulkarni/anaconda3/lib/python3.6/site-packages/jupyterlab
    JupyterLab v0.27.0
    Known labextensions:
    [I 15:47:32.804 NotebookApp] Running the core application with no additional extensions or settings
    [I 15:47:32.812 NotebookApp] Serving notebooks from local directory: /Users/pavanpkulkarni
    [I 15:47:32.812 NotebookApp] 0 active kernels
    [I 15:47:32.812 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=9a83111e557ef32ca78e9eec82804d7af61ef0cab76ff864
    [I 15:47:32.812 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
    [C 15:47:32.817 NotebookApp]
    
        Copy/paste this URL into your browser when you connect for the first time,
        to login with a token:
            http://localhost:8888/?token=9a83111e557ef32ca78e9eec82804d7af61ef0cab76ff864
    [I 15:47:32.991 NotebookApp] Accepting one-time-token-authenticated connection from ::1
    

References:

  1. https://en.wikipedia.org/wiki/Python_(programming_language)
  2. http://docs.python-guide.org/en/latest/starting/install3/osx/
  3. https://www.anaconda.com/download/#macos
  4. http://jupyter.org/