Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation error in JupyterNotebook :GMTCLibNotFoundError #1485

Closed
maihao14 opened this issue Sep 5, 2021 · 6 comments
Closed

Installation error in JupyterNotebook :GMTCLibNotFoundError #1485

maihao14 opened this issue Sep 5, 2021 · 6 comments
Labels
question Further information is requested

Comments

@maihao14
Copy link

maihao14 commented Sep 5, 2021

I install PyGMT in Google Colab (an online JupyterNotebook). When I tried to import pygmt, it will raise error

Full code that generated the error

!pip install pygmt
import pygmt

Full error message

---------------------------------------------------------------------------
GMTCLibNotFoundError                      Traceback (most recent call last)
<ipython-input-3-1f69d3ccfa65> in <module>()
----> 1 import pygmt
      2 pygmt.test()

5 frames
/usr/local/lib/python3.7/dist-packages/pygmt/clib/loading.py in load_libgmt(lib_fullnames)
     57 
     58     if error:
---> 59         raise GMTCLibNotFoundError("\n".join(error_msg))
     60 
     61     return libgmt

GMTCLibNotFoundError: Error loading GMT shared library at 'libgmt.so'.
libgmt.so: cannot open shared object file: No such file or directory

System information

The installation process runs successfully. But it seems cannot find GMT dependencies as above described.

!pip install pygmt

Collecting pygmt
  Downloading pygmt-0.4.1-py3-none-any.whl (267 kB)
     |████████████████████████████████| 267 kB 2.3 MB/s 
Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from pygmt) (1.1.5)
Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.7/dist-packages (from pygmt) (1.19.5)
Requirement already satisfied: netCDF4 in /usr/local/lib/python3.7/dist-packages (from pygmt) (1.5.7)
Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from pygmt) (21.0)
Requirement already satisfied: xarray in /usr/local/lib/python3.7/dist-packages (from pygmt) (0.18.2)
Requirement already satisfied: cftime in /usr/local/lib/python3.7/dist-packages (from netCDF4->pygmt) (1.5.0)
Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->pygmt) (2.4.7)
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas->pygmt) (2018.9)
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->pygmt) (2.8.2)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->pygmt) (1.15.0)
Requirement already satisfied: setuptools>=40.4 in /usr/local/lib/python3.7/dist-packages (from xarray->pygmt) (57.4.0)
Installing collected packages: pygmt
Successfully installed pygmt-0.4.1```
@maihao14 maihao14 added the bug Something isn't working label Sep 5, 2021
@welcome
Copy link

welcome bot commented Sep 5, 2021

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

@maihao14
Copy link
Author

maihao14 commented Sep 5, 2021

A quick update
using conda install pygmt will not raise this error.

But when you use pip install pygmt , i,e., in macOS, it cannot find GMT shared library.

I really want to know how to fix this? Because if I insert pygmt as a dependent package of another python package. It will automatically start pip install pygmt in its setup.py method. And raise error when the package is imported.

And I didn't understand how to finish this procedure in a JupyterNotebook or macOS terminal:

Finding the GMT shared library
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 GMT_LIBRARY_PATH environment variable. This should be set to the directory where libgmt.so, libgmt.dylib or gmt.dll can be found for Linux, macOS and Windows, respectively. e.g., on a command line, run:

# Linux/macOS
export GMT_LIBRARY_PATH=$HOME/anaconda3/envs/pygmt/lib
# Windows
set "GMT_LIBRARY_PATH=C:\Users\USERNAME\Anaconda3\envs\pygmt\Library\bin\"

@weiji14 weiji14 added question Further information is requested and removed bug Something isn't working labels Sep 5, 2021
@weiji14
Copy link
Member

weiji14 commented Sep 5, 2021

Hi @maihao14, thanks for trying PyGMT! So using pip install pygmt only won't work, because pygmt is a wrapper for GMT, which means you will need to install GMT as well (following https://www.pygmt.org/v0.4.1/install.html#installing-gmt-and-other-dependencies). Note that GMT is a C program, and thus cannot be installed using pip install, you will either need to use conda to install the GMT package or download an installer from https://www.generic-mapping-tools.org/download.

To answer your questions though:

I install PyGMT in Google Colab (an online JupyterNotebook). When I tried to import pygmt, it will raise error

Using PyGMT in colab is a bit tricky, but you can look at GenericMappingTools/try-gmt#17 (comment) for an idea on how to handle the installation.

Because if I insert pygmt as a dependent package of another python package. It will automatically start pip install pygmt in its setup.py method. And raise error when the package is imported.

I see that you have been working on this at maihao14/QuakeLabeler@6176b43. It is ok to use pygmt as a dependency in setup.py or requirements.txt, but again, the user installing the Python package will also need to install the GMT C program separately, because GMT cannot be pip installed.

My recommendation for your package would be to use conda install -c conda-forge pygmt (which installs both GMT and PyGMT), or if you want to be fancy, do:

conda activate pygmt-env        # activate virtual environment
conda install -c conda-forge gmt  # to install the GMT C package
pip install pygmt                     # install PyGMT

This advanced mixing of conda/pip is similar to what we use at

conda install gmt=6.2.0 numpy pandas xarray netCDF4 packaging \
ipython make myst-parser geopandas \
sphinx sphinx-copybutton sphinx-gallery sphinx_rtd_theme
# Show installed pkg information for postmortem diagnostic
- name: List installed packages
run: conda list
# Download cached remote files (artifacts) from GitHub
- name: Download remote data from GitHub
uses: dawidd6/[email protected]
with:
workflow: cache_data.yaml
workflow_conclusion: success
name: gmt-cache
path: .gmt
# Move downloaded files to ~/.gmt directory and list them
- name: Move and list downloaded remote files
run: |
mkdir -p ~/.gmt
mv .gmt/* ~/.gmt
# Change modification times of the two files, so GMT won't refresh it
touch ~/.gmt/server/gmt_data_server.txt ~/.gmt/server/gmt_hash_server.txt
ls -lhR ~/.gmt
# Install the package that we want to test
- name: Install the package
run: |
python setup.py sdist --formats=zip
pip install dist/*
.

Hopefully that helps with your problem. Sorry that the installation could not be more straightforward to understand, but let us know if you are still confused.

@maihao14
Copy link
Author

maihao14 commented Sep 6, 2021

Thanks for @weiji14, above problems are all solved!
As for using pygmt , I already apply conda install -c conda-forge pygmt . Everything runs perfectly.
Just one more question, if we use conda install -c conda-forge pygmt to install pygmt as a dependency, do we still need to write pygmt into setup.py or requirements.txt? Will it raise an error? Or nothing will happen?

@weiji14
Copy link
Member

weiji14 commented Sep 6, 2021

Thanks for @weiji14, above problems are all solved!
As for using pygmt , I already apply conda install -c conda-forge pygmt . Everything runs perfectly.

Glad to here it works 😁

Just one more question, if we use conda install -c conda-forge pygmt to install pygmt as a dependency, do we still need to write pygmt into setup.py or requirements.txt? Will it raise an error? Or nothing will happen?

I think it's safe to write pygmt into setup.py. As long as you do conda install -c conda-forge pygmt before pip install, there shouldn't be an error. You may want to look at this blog post: https://www.anaconda.com/blog/using-pip-in-a-conda-environment and https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/pip-interoperability.html for details. Personally, I would recommend running conda config --set pip_interop_enabled True (before doing any pip install in a conda environment).

P.S. Try following GPSconverter which lists pygmt in their setup.py at https://github.com/carmelosammarco/GPSconverter/blob/a61b80c7ffa84647bee3b3ea41d96f22c7ca7510/setup.py#L40. See also their install instructions at https://github.com/carmelosammarco/GPSconverter/tree/a61b80c7ffa84647bee3b3ea41d96f22c7ca7510#installation which mentions using conda install before pip install package.

@maihao14
Copy link
Author

maihao14 commented Sep 7, 2021

Problem solved!
Thanks for @weiji14 suggestions, detailed and thorough.
Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants