Skip to content

MTPy installation guide for Windows 10 and Ubuntu 18.04

Alison Kirkby edited this page Feb 10, 2021 · 15 revisions

Installation (02-04-2020)

Note about PyPi Installation

MTPy has a PyPi release. In the installation guide below, it's possible to substitute installing from the repository with installing from PyPi using:

  • pip install mtpy

At the current time this is not recommended as the PyPi release is outdated. It is recommended to install from the repository to get the latest development code.

Windows

This guide will explain how to install MTPy on a Windows 10 system using Anaconda and Python 3.7.

Using Anaconda Prompt

If you are comfortable using a terminal, the installation can be completed using an Anaconda Prompt.

  • Open Anaconda Prompt
  • Create a new environment using conda create --name mtpy
  • Activate the environment using conda activate mtpy
  • Install required packages:
    • conda install gdal libgdal geopandas netcdf4 pyyaml
    • pip install obspy
  • Install mtpy using the instructions in the GUI section

Using Anaconda GUI

Alternatively, the installation of required packages can be completed using the Anaconda GUI.

Creating a new environment

  • After installing Anaconda, open the Anaconda Navigator app
  • In the left sidebar, select Environments, then at the bottom of the window select Create
  • Give your new environment a suitable name and select Python 3.7 as the package, then press the green Create button to confirm:

Installing packages

  • Select the environment you have created from the list of available environments
  • In the packages window to the right, select Not installed from the drop down and enter gdal in the search field
  • Select the checkboxes next to gdal and libgdal, then click the Apply button in the lower right corner
  • A window will display confirming dependencies to install, click Apply
  • Repeat the process for the following additional packages:
    • geopandas
    • netcdf4
    • pyyaml

Installing obspy

  • For the next step, click the arrow next to your environment name select Open Terminal

  • You are now in a command prompt with your created Python environment active
  • Run the command pip install obspy

Installing mtpy

This can be completed in the Anaconda terminal, or your preferred Windows git client (e.g. git bash)

  • Change directory to the location where you want the mtpy code to be cloned to
    • The Anaconda terminal is a Windows command prompt, so type DRIVE_LETTER: to change to the appropriate drive and cd path\to\directory to change directories.
  • Run the command git clone https://www.github.com/MTgeophysics/mtpy
  • Once cloned, move into the cloned mtpy directory with cd mtpy

Run mtpy in desired app

Now that mtpy has been installed into your environment, you can launch applications from Anaconda Navigator from within this environment and they will have access to mtpy.

  • Click Home on the left sidebar of Anaconda Navigator
  • In the Applications on drop down menu, select your created environment
  • Install and launch your desired software

For example, you can run mtpy in Spyder through Anaconda Navigator:

Note: if you have previously used mtpy with Windows, you may be used to putting os.chdir('/path/to/mtpy') in your scripts. Now that mtpy is installed as a package in your environment, you no longer need to do this. So long as you launch your application using the created environment, you can import mtpy like any other package without changing directory.

Updating mtpy

GitHub

  • Open an Anaconda Prompt in your mtpy environment (or your preferred git client, but ensure your mtpy environment is active).
  • Change directory to the mtpy directory containing the mtpy code
  • Checkout the desired branch with git pull origin <branch-name> (e.g. git checkout develop)
  • Run the command git pull origin <branch-name>
    • If you have local changes that are preventing you from switching branches or pulling new code, and you wish to keep them, first run git stash. This will stash your changes and clean your working directory. Once you have changed branches and updated the code, you can recover your changes using git stash pop, which will reapply them.
    • If you don't mind losing the changes, run git checkout -- . to revert your changes and then checkout and pull the new code.
  • Reinstall mtpy by running the command pip install .
    • Tip: if you are frequently pulling code changes, or making your own changes to mtpy, then install with pip install -e .. The -e tells pip to install in editable mode, so changes will automatically be incorporated into the package without having to reinstall after every change.

Use MTPy

You can now run MTPy workflows as described in the user guide.

Linux

These instructions have been tested with Ubuntu 18.04. If you are using a different distribution, the name of your package manager may be different as well as available package versions.

mtpy can be installed on Linux with or without Anaconda. If you're unsure, it's best to use Anaconda as it will handle OS dependencies for you.

Using Anaconda GUI

If you use a GUI desktop environment with your Linux OS, then you can download Anaconda for your OS (https://www.anaconda.com/distribution/) and follow the Anaconda GUI instructions above.

Using Anaconda in the terminal

Install Anaconda and setup environment

If you are running Ubuntu server or prefer to use the terminal, follow these instructions:

  • Visit https://repo.anaconda.com/archive/ to find the latest or desired Linux install script (e.g. Anaconda3-2020.02-Linux-x86_64.sh)
  • Download the script with curl -O https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh (substituting the script for your desired version)
  • Run the script with ./Anaconda3-2020.02-Linux-x86_64.sh and follow the prompts
  • Create a new environment using conda create --name mtpy
  • Activate the environment using conda activate mtpy
  • Install required packages:
    • conda install gdal libgdal geopandas netcdf4 pyyaml
    • pip install obspy

Install mtpy

GitHub install
  • Change directory to the location where you want the mtpy code to be cloned to
  • Run the command git clone https://www.github.com/MTgeophysics/mtpy
  • Once cloned, move into the cloned mtpy directory with cd mtpy
  • Run the command pip install .
    • This command installs the mtpy code as a package in your created Python environment

Install without Anaconda

If you prefer to manage your own Python environments and packages, mtpy can be installed without Anaconda.

Install Python 3.7

You can choose to install Python 3.7 from source, or follow these instructions to install from the deadsnakes ppa:

  • sudo apt update
  • sudo apt install software-properties-common
  • sudo add-apt-repository ppa:deadsnakes/ppa
    • This command adds the deadsnakes repository to your package manager. This repository maintains versions of Python for Ubuntu that aren't available by default.
  • sudo apt install python3.7

Install GDAL and gcc

  • sudo apt install gdal-bin
  • sudo apt install libgdal-dev
  • sudo apt install build-essential
    • This will install gcc, required for building some of mtpy's Python dependencies
  • Add GDAL to your CPLUS_INCLUDE_PATH and C_INCLUDE_PATH
    • export CPLUS_INCLUDE_PATH=/usr/include/gdal:$CPLUS_INCLUDE_PATH
    • export C_INCLUDE_PATH=/usr/include/gdal:$C_INCLUDE_PATH
      • Add these commands to your .bashrc so they are automatically applied when you start a new shell

Create and setup virtual environment

  • Change directory to where you want your mtpy Python virtual environment to exist
  • Create the environment using python3.7 -m venv mtpy
  • Activate the environment using source mtpy/bin/activate
  • Upgrade pip and setuptools with pip install -U pip setuptools
  • Install dependencies:
    • pip install geopandas netcdf4 obspy pyyaml gdal

Install mtpy

Follow the Using Anaconda in the terminal mtpy install instructions above.

Updating mtpy

Follow the Updating mtpy instructions in the Windows section above. You can use an Anaconda Prompt if you are running Anaconda Navigator, or substitute its use with your Linux terminal (ensure your mtpy environment is active!).

Use MTPy

You can now run MTPy workflows as described in the user guide.