Installing

Quickstart

The fastest way to install PyGMT is with the mamba or conda package manager which takes care of setting up a virtual environment, as well as the installation of GMT and all the dependencies PyGMT depends on:

mamba create --name pygmt --channel conda-forge pygmt
conda create --name pygmt --channel conda-forge pygmt

To activate the virtual environment, you can do:

mamba activate pygmt
conda activate pygmt

After this, check that everything works by running the following in a Python interpreter (e.g., in a Jupyter notebook):

import pygmt
pygmt.show_versions()
Hide code cell output
PyGMT information:
  version: v0.13.1.dev171+g97185e84
System information:
  python: 3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 16:05:46) [GCC 13.3.0]
  executable: /home/runner/micromamba/envs/pygmt/bin/python
  machine: Linux-6.5.0-1025-azure-x86_64-with-glibc2.35
Dependency information:
  numpy: 2.1.3
  pandas: 2.2.3
  xarray: 2024.10.0
  netCDF4: 1.7.1
  packaging: 24.2
  contextily: 1.6.2
  geopandas: 0.14.4
  IPython: 8.29.0
  pyarrow: 18.0.0
  rioxarray: 0.17.0
  gdal: 3.9.3
  ghostscript: 10.04.0
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: /home/runner/micromamba/envs/pygmt/share/gmt
  plugin dir: /home/runner/micromamba/envs/pygmt/lib/gmt/plugins
  library path: /home/runner/micromamba/envs/pygmt/lib/libgmt.so
  cores: 4
  grid layout: rows
  image layout: 
  binary version: 6.5.0

You are now ready to make your first figure! Start by looking at our Intro, Tutorials, and Gallery. Good luck!

Note

The sections below provide more detailed, step by step instructions to install and test PyGMT for those who may have a slightly different setup or want to install the latest development version.

Which Python?

PyGMT is tested to run on Python >=3.10.

We recommend using the Miniforge Python distribution to ensure you have all dependencies installed and the mamba package manager in the base environment. Installing Miniforge does not require administrative rights to your computer and doesn’t interfere with any other Python installations on your system.

Which GMT?

PyGMT requires Generic Mapping Tools (GMT) >=6.4.0 since there are many changes being made to GMT itself in response to the development of PyGMT.

Compiled conda packages of GMT for Linux, macOS and Windows are provided through conda-forge. Advanced users can also build GMT from source instead.

We recommend following the instructions further on to install GMT 6.

Dependencies

PyGMT requires the following packages to be installed:

Note

For the minimum supported versions of the dependencies, please see Minimum Supported Versions.

Note

Some optional dependencies (e.g., IPython, GeoPandas) add more functionality to PyGMT. For a complete list of the optional dependencies, refer to Ecosystem.

Installing GMT and other dependencies

Before installing PyGMT, we must install GMT itself along with the other dependencies. The easiest way to do this is via the mamba or conda package manager. We recommend working in an isolated virtual environment to avoid issues with conflicting versions of dependencies.

First, we must configure conda to get packages from the conda-forge channel:

conda config --prepend channels conda-forge

Now we can create a new virtual environment with Python and all our dependencies installed (we’ll call it pygmt but feel free to change it to whatever you want):

mamba create --name pygmt python=3.12 numpy pandas xarray netcdf4 packaging gmt
conda create --name pygmt python=3.12 numpy pandas xarray netcdf4 packaging gmt

Activate the environment by running the following (do not forget this step!):

mamba activate pygmt
conda activate pygmt

From now on, all commands will take place inside the virtual environment called pygmt and won’t affect your default base installation.

Tip

You can also enable more PyGMT functionality by installing PyGMT’s optional dependencies in the environment.

mamba install contextily geopandas ipython pyarrow rioxarray
conda install contextily geopandas ipython pyarrow rioxarray

Installing PyGMT

Now that you have GMT installed and your virtual environment activated, you can install PyGMT using any of the following methods.

Using pip

This installs the latest stable release from PyPI:

python -m pip install pygmt

Tip

You can also run python -m pip install pygmt[all] to install PyGMT with all of its optional dependencies.

Alternatively, you can install the latest development version from TestPyPI:

python -m pip install --pre --extra-index-url https://test.pypi.org/simple/ pygmt

To upgrade the installed stable release or development version to be the latest one, just add --upgrade to the corresponding command above.

Any of the above methods (mamba/conda/pip) should allow you to use the PyGMT package from Python.

Testing your install

To ensure that PyGMT and its dependencies are installed correctly, run the following in your Python interpreter:

import pygmt
pygmt.show_versions()
Hide code cell output
PyGMT information:
  version: v0.13.1.dev171+g97185e84
System information:
  python: 3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 16:05:46) [GCC 13.3.0]
  executable: /home/runner/micromamba/envs/pygmt/bin/python
  machine: Linux-6.5.0-1025-azure-x86_64-with-glibc2.35
Dependency information:
  numpy: 2.1.3
  pandas: 2.2.3
  xarray: 2024.10.0
  netCDF4: 1.7.1
  packaging: 24.2
  contextily: 1.6.2
  geopandas: 0.14.4
  IPython: 8.29.0
  pyarrow: 18.0.0
  rioxarray: 0.17.0
  gdal: 3.9.3
  ghostscript: 10.04.0
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: /home/runner/micromamba/envs/pygmt/share/gmt
  plugin dir: /home/runner/micromamba/envs/pygmt/lib/gmt/plugins
  library path: /home/runner/micromamba/envs/pygmt/lib/libgmt.so
  cores: 4
  grid layout: rows
  image layout: 
  binary version: 6.5.0
fig = pygmt.Figure()
fig.coast(projection="N15c", region="g", frame=True, land="tan", water="lightblue")
fig.text(position="MC", text="PyGMT", font="80p,Helvetica-Bold,red@75")
fig.show()
_images/a9bb1433fed9d9d76328850660ff89d8093e2996d8363e267481ceb0f94fb8ca.png

You should see a global map with land and water masses colored in tan and lightblue respectively. On top, there should be the semi-transparent text “PyGMT”. If the semi-transparency does not show up, there is probably an incompatibility between your GMT and Ghostscript versions. For details, please run pygmt.show_versions() and see Not working transparency.

Common installation issues

If you have any issues with the installation, please check out the following common problems and solutions.

“Error loading GMT shared library at …”

Sometimes, PyGMT will be unable to find the correct version of the GMT shared library (libgmt). This can happen if you have multiple versions of GMT installed.

You can tell PyGMT exactly where to look for libgmt by setting the environment variable GMT_LIBRARY_PATH to the directory where libgmt.so, libgmt.dylib or gmt.dll can be found on Linux, macOS or Windows, respectively.

For Linux/macOS, add the following line to your shell configuration file (usually ~/.bashrc for Bash on Linux and ~/.zshrc for Zsh on macOS):

export GMT_LIBRARY_PATH=$HOME/miniforge3/envs/pygmt/lib

For Windows, add the environment variable GMT_LIBRARY_PATH following these instructions and set its value to a path like:

C:\Users\USERNAME\Miniforge3\envs\pygmt\Library\bin\

ModuleNotFoundError in Jupyter notebook environment

If you can successfully import PyGMT in a Python interpreter or IPython, but get a ModuleNotFoundError when importing PyGMT in Jupyter, you may need to activate your pygmt virtual environment (using mamba activate pygmt or conda activate pygmt) and install a pygmt kernel following the commands below:

python -m ipykernel install --user --name pygmt  # install virtual environment properly
jupyter kernelspec list --json

After that, you need to restart Jupyter, open your notebook, select the pygmt kernel and then import pygmt.

Not working transparency

It is known that some combinations of GMT and Ghostscript versions cause issues, especially regarding transparency. If the transparency doesn’t work in your figures, please check your GMT and Ghostscript versions (you can run pygmt.show_versions()). We recommend:

  • Ghostscript 9.53-9.56 for GMT 6.4.0 (or below)

  • Ghostscript 10.03 or later for GMT 6.5.0