WEMC Tech Blog #1: Installing Python and Packages

In this series of technical blog posts, we 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:

[pastacode lang=”python” manual=”python3%20–version” message=”” highlight=”” provider=”manual”/]

 

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

[pastacode lang=”python” manual=”brew%20install%20python3″ message=”” highlight=”” provider=”manual”/]

 

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:

[pastacode lang=”python” manual=”pip3%20install%20packagename” message=”” highlight=”” provider=”manual”/]

 

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:

[pastacode lang=”python” manual=”import%20netCDF4%0Aimport%20matplotlib%0Aimport%20numpy%20as%20np%0Aimport%20xarray%20as%20xr%0A” message=”” highlight=”” provider=”manual”/]

 

by Luke Sanger (WEMC, 2018)

Recommended Posts