Colabtools: can't install package `cartopy`

Created on 13 Mar 2018  路  8Comments  路  Source: googlecolab/colabtools

I tried installing Scitools' cartopy package

!pip install geos
!pip install pyproj
!pip install cartopy

and the installer reports errors.

Requirement already satisfied: geos in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: lxml in /usr/local/lib/python3.6/dist-packages (from geos)
Requirement already satisfied: flask in /usr/local/lib/python3.6/dist-packages (from geos)
Requirement already satisfied: click>=2.0 in /usr/local/lib/python3.6/dist-packages (from flask->geos)
Requirement already satisfied: Werkzeug>=0.7 in /usr/local/lib/python3.6/dist-packages (from flask->geos)
Requirement already satisfied: Jinja2>=2.4 in /usr/local/lib/python3.6/dist-packages (from flask->geos)
Requirement already satisfied: itsdangerous>=0.21 in /usr/local/lib/python3.6/dist-packages (from flask->geos)
Requirement already satisfied: MarkupSafe in /usr/local/lib/python3.6/dist-packages (from Jinja2>=2.4->flask->geos)
Requirement already satisfied: pyproj in /usr/local/lib/python3.6/dist-packages
Collecting cartopy
  Using cached Cartopy-0.16.0.tar.gz
    Complete output from command python setup.py egg_info:
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Plex/Scanners.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Plex/Actions.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Pythran.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Lexicon.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Scanning.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Parsing.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Visitor.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/FlowControl.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Code.py because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Runtime/refnanny.pyx because it changed.
    Compiling /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Tempita/_tempita.py because it changed.
    [ 1/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Code.py
    [ 2/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/FlowControl.py
    [ 3/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Lexicon.py
    [ 4/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Parsing.py
    [ 5/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Pythran.py
    [ 6/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Scanning.py
    [ 7/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Compiler/Visitor.py
    [ 8/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Plex/Actions.py
    [ 9/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Plex/Scanners.py
    [10/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Runtime/refnanny.pyx
    [11/11] Cythonizing /tmp/easy_install-1yz5rh__/Cython-0.27.3/Cython/Tempita/_tempita.py
    Unable to find pgen, not compiling formal grammar.
    warning: no files found matching '2to3-fixers.txt'
    warning: no files found matching 'Doc/*'
    warning: no files found matching '*.pyx' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.pxd' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.pxd' under directory 'Cython/Utility'

    Installed /tmp/pip-build-l42wavod/cartopy/.eggs/Cython-0.27.3-py3.6-linux-x86_64.egg
    /tmp/pip-build-l42wavod/cartopy/setup.py:178: UserWarning: Unable to determine GEOS version. Ensure you have 3.3.3 or later installed, or installation may fail.
      '.'.join(str(v) for v in GEOS_MIN_VERSION), ))
    /tmp/pip-build-l42wavod/cartopy/setup.py:234: UserWarning: Unable to determine Proj4 version. Ensure you have 4.9.0 or later installed, or installation may fail.
      '.'.join(str(v) for v in PROJ_MIN_VERSION), ))
    Proj4 version 0.0.0 is installed, but cartopy requires at least version 4.9.0.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-l42wavod/cartopy/

Most helpful comment

Yes, there seem to be a few problems here:

  1. As with your initial report, before cython is installed, pip hung with no output. I'm going to look into that.
  2. Once you get past that, you need a handful of additional packages.

I think this is a complete recipe:

!apt-get install libproj-dev proj-data proj-bin
!apt-get install libgeos-dev
!pip install cython
!pip install cartopy

LMK if that doesn't get you unstuck. (I'll keep this open for the first issue until I know more.)

All 8 comments

Yes, there seem to be a few problems here:

  1. As with your initial report, before cython is installed, pip hung with no output. I'm going to look into that.
  2. Once you get past that, you need a handful of additional packages.

I think this is a complete recipe:

!apt-get install libproj-dev proj-data proj-bin
!apt-get install libgeos-dev
!pip install cython
!pip install cartopy

LMK if that doesn't get you unstuck. (I'll keep this open for the first issue until I know more.)

oic -- the "freeze before cython is installed" was actually "craig is too impatient to wait for output to start appearing".

so the remaining issue here was cartopy install instructions; the above seems to work, and I'll add them to the install snippets.

@swnesbitt LMK if you're still blocked.

unstuck! thanks.

screenshot 2018-03-13 12 22 39

I'm having trouble installing Cartopy with the same test as above. The error printed in colab is:

Geometry must be a Point or LineString

and the error in the log is:

python3: geos_ts_c.cpp:3991: int GEOSCoordSeq_getSize_r(GEOSContextHandle_t, const geos::geom::CoordinateSequence, unsigned int): Assertion `0 != cs' failed.

See https://github.com/SciTools/cartopy/issues/1346#issuecomment-558397297:

To install in Colab on Ubuntu using pip, you need to install the library dependencies:

!apt-get install -qq libgdal-dev libproj-dev
Then !pip install cartopy works.

No luck:

!apt-get install -qq libgdal-dev libproj-dev
!pip install cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
plt.show()

produces the same error.

Mar 19, 2020, 1:08:06 PM | WARNING | WARNING:root:kernel 1cf4389e-ca0b-42cc-9c88-401640a630e9 restarted
-- | -- | --
Mar 19, 2020, 1:08:06 PM | INFO | KernelRestarter: restarting kernel (1/5), keep random ports
Mar 19, 2020, 1:08:06 PM | WARNING | python3: geos_ts_c.cpp:3991: int GEOSCoordSeq_getSize_r(GEOSContextHandle_t, const geos::geom::CoordinateSequence*, unsigned int*): Assertion `0 != cs' failed.

Yes, there seem to be a few problems here:

1. As with your initial report, before cython is installed, `pip` hung with no output. I'm going to look into that.

2. Once you get past that, you need a handful of additional packages.

I think this is a complete recipe:

!apt-get install libproj-dev proj-data proj-bin
!apt-get install libgeos-dev
!pip install cython
!pip install cartopy

LMK if that doesn't get you unstuck. (I'll keep this open for the first issue until I know more.)

Had to install one more

apt install python3-dev

I recently hit issues with this too, specifically the issue @jrieffel mentioned, which I was I was able to resolve by following the advice from https://github.com/SciTools/cartopy/issues/871.

In case it's useful to others my install is:

# not using `python-cartopy` package as it doesn't include all build dependencies
!apt-get install libproj-dev proj-bin proj-data
!apt-get install libgeos-dev

# shapely needs to be reinstalled to use the same geos install as cartopy (https://github.com/SciTools/cartopy/issues/871)
!pip uninstall -y shapely
!pip install --no-binary shapely shapely
!pip install cartopy

This then produces output with something like:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([80, 170, -45, 30], crs=ccrs.PlateCarree())

ax.stock_img()
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.COASTLINE)

plt.show()
Was this page helpful?
0 / 5 - 0 ratings