Skip to content

pygmt import error on google colaboratory #17

Closed

Description

@liamtoney

After running the cell which installs conda etc. the import pygmt command fails with:

Screen Shot 2021-02-17 at 12 05 48 PM

Activity

  1. seisman commented on Feb 17, 2021

    @seisman
    Member

    I also noticed it yesterday. It's weird that the commands in the notebook install "python 3.9" but the python version in the error message says it's python3.6.

  2. added
    bug
    on Jun 6, 2021
  3. changed the title [-]pygmt import error[/-] [+]pygmt import error on google collaboratory[/+] on Jun 6, 2021
  4. weiji14 commented on Jun 6, 2021

    @weiji14
    Member

    I also noticed it yesterday. It's weird that the commands in the notebook install "python 3.9" but the python version in the error message says it's python3.6.

    After doing some reading (e.g. https://towardsdatascience.com/conda-google-colab-75f7c867a522), it seems that we need to pin conda's Python version to be the same as that on Google Collaboratory (currently Python 3.7) instead of the Miniconda default (Python 3.9). However, I tried getting a Python 3.7 installer from https://repo.anaconda.com/miniconda/, and it still produces a DistributionNotFound error (as Liam and a forum user at https://forum.generic-mapping-tools.org/t/installing-pygmt-on-google-colab/898/12 reported). So needs a bit more work somehow.

  5. changed the title [-]pygmt import error on google collaboratory[/-] [+]pygmt import error on google colaboratory[/+] on Jun 19, 2021
  6. andrebelem commented on Jun 20, 2021

    @andrebelem

    I managed to use pygmt in the colab "installing GMT6 fresh".
    Take a look at https://github.com/andrebelem/pythonverse/blob/main/PyGMT_on_COLAB.ipynb and feel free to incorporate it in the try-gmt.

  7. I-Hamama commented on Mar 4, 2024

    @I-Hamama

    Try to reinstall GMT and ghost script and refer to the libgmt.so.6

    !sudo apt-get update
    !sudo apt-get install gmt gmt-dcw gmt-gshhg
    !sudo apt-get install -y ghostscript
    !pip install pygmt
    import os
    !ln -s /lib/x86_64-linux-gnu/libgmt.so.6 /lib/x86_64-linux-gnu/libgmt.so
    os.environ['LD_LIBRARY_PATH'] = ' /lib/x86_64-linux-gnu/libgmt.so'

    Should work with these commands

  8. andrebelem commented on Mar 4, 2024

    @andrebelem

    Two years ago, I created an example of how to use PyGMT in COLAB. I've updated the example now in the latest version of COLAB (March 2024), which you can see here: https://github.com/andrebelem/pythonverse/blob/main/Using_pygmt_in_COLAB_[version_2023].ipynb.

    Essentially, you'll install Conda, and then GMT/PyGMT. Note that this should be done in parts, and the first two cells take about 3 minutes to install everything. Good luck.

  9. I-Hamama commented on Mar 4, 2024

    @I-Hamama

    PyGMT can't recognize to the libgmt.so under Google Colab. So, it is important to refer the path of libgmt.so in linux system which google are using

    !ln -s /lib/x86_64-linux-gnu/libgmt.so.6 /lib/x86_64-linux-gnu/libgmt.so

    What I did just adding alias of libgmt.so.6 and I reinstalled the GMT and ghost script.

    It works well. I didn't try to use conda but good to know 2 ways of solving the problem

    Thanks

  10. andrebelem commented on Mar 4, 2024

    @andrebelem

    Installing GMT using !sudo apt-get install gmt gmt-dcw gmt-gshhg takes much longer than using conda/mamba, which causes most users to give up on the process. I myself abandoned the idea of apt install some time ago. I recommend using conda install.

  11. SeismoFelix commented on Feb 11, 2026

    @SeismoFelix

    Hello @andrebelem

    I just followed your Notebook instructions and failed. I wonder if Colab has changed since the last time you replied to this issue.

    Best regards,

    Felix

    Image
  12. SeismoFelix commented on Feb 11, 2026

    @SeismoFelix

    I managed to get PyGMT working in Google Colab without using condacolab.

    The issue seems to be a version mismatch between the system libraries available in Colab's default Linux environment and the latest PyGMT release.

    Since Colab runs on an LTS version of Ubuntu, so the official apt repositories only provide GMT 6.4.0. The latest version of PyGMT requires GMT 6.5.0+, which causes a GMTVersionError if you try to install it directly.

    To fix this, I installed the system dependencies via apt and then pinned PyGMT to v0.11.0, which is the last version compatible with GMT 6.4.0.

    Here is a link to the Notebook I just created and worked for me:

    https://colab.research.google.com/drive/1BFWdQJyeAJeI2xZPXEK0G8JfxZmCy7Q0?usp=sharing

  13. naliboff commented on Feb 23, 2026

    @naliboff

    @SeismoFelix - Thank you, this worked perfectly on my end and the dependencies installation took less than 30 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions