Search code examples
pythoncartopy

When importing Cartopy ImportError: DLL load failed while importing trace: The specified module could not be found


I installed Christoph Gohlke's prebuilt wheel Cartopy‑0.20.2‑cp39‑cp39‑win_amd64.whl using pip in an active virtual environment. The environment is using Python 3.9.5. When trying to import Cartopy I get the error message below. This used to work before and now it no longer works and I can't figure out why. Does anyone know what the issue could be or what I'm missing?

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 import cartopy
      2 import cartopy.crs as ccrs
      3 import cartopy.io.img_tiles as cimgt

File ~\Downloads\GitHub\Project\venv\lib\site-packages\cartopy\__init__.py:110, in <module>
    105     pass
    108 # Commonly used sub-modules. Imported here to provide end-user
    109 # convenience.
--> 110 import cartopy.crs
    111 import cartopy.feature

File ~\Downloads\GitHub\Project\venv\lib\site-packages\cartopy\crs.py:27, in <module>
     24 from pyproj.exceptions import ProjError
     25 from shapely.prepared import prep
---> 27 import cartopy.trace
     30 try:
     31     # https://github.com/pyproj4/pyproj/pull/912
     32     from pyproj.crs import CustomConstructorCRS as _CRS

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

Solution

  • As mentioned by cgohlke in the comments, installing the wheels of shapely and pyproj from his website solves the issue.

    If the libraries are already installed, use --force-reinstall to overwrite the existing installations.