ModuleNotFoundError: No module named 'pygmt'

Hello! I’m new to both python and gmt. I installed pygmt 0.3.0 with anaconda following all instructions but when I try to import pygmt I get an error “no module named pygmt” … During the installation everything went fine, can anyone help me with this issue?.
Below is the run result in jupyter when the kernel has been changed from Python 3 to pygmt to test the program. Thank you.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\anaconda3\envs\pygmt\lib\site-packages\numpy\core\__init__.py in <module>
     21 try:
---> 22     from . import multiarray
     23 except ImportError as exc:

~\anaconda3\envs\pygmt\lib\site-packages\numpy\core\multiarray.py in <module>
     11 
---> 12 from . import overrides
     13 from . import _multiarray_umath

~\anaconda3\envs\pygmt\lib\site-packages\numpy\core\overrides.py in <module>
      6 
----> 7 from numpy.core._multiarray_umath import (
      8     add_docstring, implement_array_function, _get_implementing_args)

ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-f58669fae37f> in <module>
----> 1 import pygmt

~\anaconda3\envs\pygmt\lib\site-packages\pygmt\__init__.py in <module>
     13 
     14 # Import modules to make the high-level GMT Python API
---> 15 from pygmt import datasets
     16 from pygmt.figure import Figure
     17 from pygmt.modules import GMTDataArrayAccessor, config

~\anaconda3\envs\pygmt\lib\site-packages\pygmt\datasets\__init__.py in <module>
      3 # Load sample data included with GMT (downloaded from the GMT cache server).
      4 
----> 5 from pygmt.datasets.earth_relief import load_earth_relief
      6 from pygmt.datasets.tutorial import (
      7     load_japan_quakes,

~\anaconda3\envs\pygmt\lib\site-packages\pygmt\datasets\earth_relief.py in <module>
      5 The grids are available in various resolutions.
      6 """
----> 7 import xarray as xr
      8 from pygmt.exceptions import GMTInvalidInput
      9 from pygmt.helpers import kwargs_to_strings

~\anaconda3\envs\pygmt\lib\site-packages\xarray\__init__.py in <module>
      1 import pkg_resources
      2 
----> 3 from . import testing, tutorial, ufuncs
      4 from .backends.api import (
      5     load_dataarray,

~\anaconda3\envs\pygmt\lib\site-packages\xarray\testing.py in <module>
      3 from typing import Hashable, Set, Union
      4 
----> 5 import numpy as np
      6 import pandas as pd
      7 

~\anaconda3\envs\pygmt\lib\site-packages\numpy\__init__.py in <module>
    143     from . import _distributor_init
    144 
--> 145     from . import core
    146     from .core import *
    147     from . import compat

~\anaconda3\envs\pygmt\lib\site-packages\numpy\core\__init__.py in <module>
     46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
     47         __version__, exc)
---> 48     raise ImportError(msg)
     49 finally:
     50     for envkey in env_added:

ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "C:\Users\Lenovo\anaconda3\envs\pygmt\python.exe"
  * The NumPy version is: "1.20.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.

Hi @Richard, thanks for trying out PyGMT! I’ve encountered this issue before, and there’s a few possible reasons for the numpy error. but my first try would be to reinstall numpy as it might have been a corrupted install (at least it usually is for me). Try running the following commands in Anaconda prompt:

conda activate pygmt
conda uninstall numpy
conda clean --all  # Remove index cache, lock files, unused cache packages, and tarballs.
conda install numpy

If that doesn’t work, have a look at some of the other solutions on https://stackoverflow.com/questions/54063285/numpy-is-already-installed-with-anaconda-but-i-get-an-importerror-dll-load-fail/58194133#58194133. Let us know if you need clarification on anything.

To make it short, it means that you lacked some “dependencies” for the libraries you wanted to use. This is a common problem when installing python packages, mainly in windows. Before trying to use any kind of library, first it is suggested to look up whether it needs another library in python “family”.

The solution is to provide the python interpreter with the path-to-your-module/library. The simplest solution is to append that python path to your sys.path list. In your notebook, first try:

import sys
sys.path.append('my/path/to/module/folder')

This isn’t a permanent change in sys.path, because when you log out, your environment is reset, so any variables you may have set are lost.

The better (and more permanent) way to solve this is to set your PYTHONPATH, which provides the interpreter with additional directories look in for python packages/modules.

from BASH type: export PYTHONPATH=/path/to/new/folder:/another/path/...../

#each path must be separated by a colon