Stream: python-questions

Topic: cartopy import error


view this post on Zulip Matt Long (Jun 09 2020 at 13:29):

I recently updated my environment and get the following error on importing cartopy:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-b0688681af7f> in <module>
     12 import matplotlib.pyplot as plt
     13
---> 14 import cartopy.crs as ccrs
     15 from cartopy.util import add_cyclic_point
     16 import cmocean

/glade/work/mclong/miniconda3/envs/krill/lib/python3.7/site-packages/cartopy/__init__.py in <module>
     94 # Commonly used sub-modules. Imported here to provide end-user
     95 # convenience.
---> 96 import cartopy.crs
     97 import cartopy.feature  # noqa: F401  (flake8 = unused import)

/glade/work/mclong/miniconda3/envs/krill/lib/python3.7/site-packages/cartopy/crs.py in <module>
     34 import six
     35
---> 36 from cartopy._crs import (CRS, Geodetic, Globe, PROJ4_VERSION,
     37                           WGS84_SEMIMAJOR_AXIS, WGS84_SEMIMINOR_AXIS)
     38 from cartopy._crs import Geocentric  # noqa: F401 (flake8 = unused import)

ImportError: libproj.so.19: cannot open shared object file: No such file or directory

Has anyone encountered this? Solutions?

view this post on Zulip Anderson Banihirwe (Jun 09 2020 at 13:42):

I am on somewhat up-to-date versions of cartopy and proj and things seem to work fine ( I tested the import)

$ conda list cartopy
# packages in environment at /glade/work/abanihi/softwares/miniconda3/envs/analysis:
#
# Name                    Version                   Build  Channel
cartopy                   0.18.0           py37h4b180d9_0    conda-forge

abanihi at casper26 in ~
$ conda list proj
# packages in environment at /glade/work/abanihi/softwares/miniconda3/envs/analysis:
#
# Name                    Version                   Build  Channel
proj                      7.0.0                h966b41f_4    conda-forge
pyproj                    2.6.1.post1      py37h34dd122_0    conda-forge

I am curious... Did you pin your proj and pyproj versions? They are a little outdated:

abanihi at casper26 in ~
$ conda list cartopy
# packages in environment at /glade/work/mclong/miniconda3/envs/krill:
#
# Name                    Version                   Build  Channel
cartopy                   0.18.0           py37h4b180d9_0    conda-forge

abanihi at casper26 in ~
$ conda list proj
# packages in environment at /glade/work/mclong/miniconda3/envs/krill:
#
# Name                    Version                   Build  Channel
proj                      6.3.1                hc80f0dc_1    conda-forge
pyproj                    2.5.0            py37he3cd046_1    conda-forge

view this post on Zulip Matt Long (Jun 09 2020 at 13:46):

no, I did not pin my proj and pyproj versions, but I bet that this is the problem. I don't include them in my specific list of dependencies.

view this post on Zulip Matt Long (Jun 09 2020 at 13:48):

Here's the environment: https://github.com/matt-long/krill-cesm-le/blob/master/environment/environment.yml

view this post on Zulip Matt Long (Jun 09 2020 at 13:48):

Can you suggest a modification?

view this post on Zulip Anderson Banihirwe (Jun 09 2020 at 13:48):

Can you suggest a modification?

I am looking into it

view this post on Zulip Anderson Banihirwe (Jun 09 2020 at 13:49):

i am inspecting the environment to see what packages may be restricting pyproj and proj to be updated

view this post on Zulip Matt Long (Jun 09 2020 at 13:50):

many thanks!

view this post on Zulip Anderson Banihirwe (Jun 09 2020 at 13:51):

Anytime!

view this post on Zulip Anderson Banihirwe (Jun 09 2020 at 13:51):

Are you using this environment file: https://github.com/matt-long/krill-cesm-le/blob/master/environment/environment.yml?

view this post on Zulip Matt Long (Jun 09 2020 at 13:52):

yes

view this post on Zulip Anderson Banihirwe (Jun 09 2020 at 14:02):

I happened to have a krill environment. I tried updating it with conda env update -f environment/environment.yml and I noticed that proj and pyproj versions didn't change i.e. before and after the update:

$ conda list proj
# packages in environment at /glade/work/abanihi/softwares/miniconda3/envs/krill:
#
# Name                    Version                   Build  Channel
proj                      7.0.0                h966b41f_3    conda-forge
pyproj                    2.6.0            py37h34dd122_1    conda-forge

I'd recommend updating the environment file with the following:

- cartopy >= 0.18.0
- proj >= 7.0.0
- pyproj >= 2.6.0

view this post on Zulip Matt Long (Jun 09 2020 at 14:05):

thanks, I'll try it

view this post on Zulip Matt Long (Jun 09 2020 at 14:58):

this seems to have fixed my import error

view this post on Zulip Matt Long (Jun 09 2020 at 14:58):

thanks!

view this post on Zulip Anderson Banihirwe (Jun 09 2020 at 15:00):

Awesome :tada:


Last updated: Jan 30 2022 at 12:01 UTC