Installing Python3 and Packages (OSX/Unix)

In this series of technical blog posts, I will be looking at using open source tools to examine energy and climate data.

The examples will be mostly using Python3 and based on OSX/Linux environment, however they should translate to Windows too.

To check if you have Python3 installed, enter the following into a terminal window:

python3 --version


If you don’t already have Python3, you can install using¬†homebrew (OSX/Linux):

brew install python3


It’s worth bearing in mind if using OSX, that it comes with python2 pre-installed, whereas Windows does not.¬† Once you have Python3 installed, use the ‘pip3 install’ command to install packages, replacing ‘packagename’ with the name of the package you are installing:

pip3 install packagename


This should keep them associated with your python3 installation. However, you might prefer organising your python versions differently, with anaconda or similar.

Packages are imported at the beginning of your program and can be used with an alias to speed up typing code, as seen below with ‘numpy as np’. In addition, separate modules from larger packages can be installed if only certain features are required and we will look at this in the next blog:

import netCDF4
import matplotlib
import numpy as np
import xarray as xr

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.