cartopy icon indicating copy to clipboard operation
cartopy copied to clipboard

cartopy possibly kills the kernel when using ipython/jupyter notebook

Open fischcheng opened this issue 8 years ago • 26 comments

I've been stuck in this issue for couple of days now.

Hereby is my system info: conda info -all: platform : osx-64 (10.11.3) conda version : 4.0.4 conda-build version : 1.14.1 python version : 3.4.4.final.0 requests version : 2.7.0 cartopy version: 0.13.0

whenever I tried plotting figures, the kernel within the notebook just restart and showing this message: The kernel appears to have died. It will restart automatically. (I can still plot using matplotlib, just not cartopy or basemap.)

and two lines like these: ERROR:shapely.geos:Geometry must be a Point or LineString ERROR:shapely.geos:Geometry must be a Point or LineString

However, the exact same code works on the python2.7 system on the other machine (also Anaconda but python 2.7.9). but the same issue occurs on the python 2.7.9 on my another mac (so no python version issue). I'm thinking it might be OS X issue, or conflict between cartopy and jupyter notebook.

I've been working with cartopy for quite a while, yet this issue is new. Maybe caused by some recent updates? I've tried updating conda python, uninstall reinstall cartopy, geos, shapely, matplotlib and so on, yet the same issue persists. Please help me out! Thank you!

fischcheng avatar Mar 15 '16 16:03 fischcheng

I am struggling with the exact same problem. A fresh, empty jupyter notebook with only the following lines crashes when I execute the cell:

import matplotlib.pyplot as plt
import cartopy
fig = plt.figure(figsize=(6, 6))
ax = plt.subplot(1, 1, 1, projection=cartopy.crs.PlateCarree())

The log reports:

[I 20:26:36.474 NotebookApp] Creating new notebook in 
[I 20:26:37.316 NotebookApp] Kernel started: 818496ab-8873-4231-8a12-026f96560b4f
ERROR:shapely.geos:Geometry must be a Point or LineString
ERROR:shapely.geos:Geometry must be a Point or LineString
Assertion failed: (0 != cs), function GEOSCoordSeq_getSize_r, file geos_ts_c.cpp, line 3612.
[I 20:27:19.318 NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel 818496ab-8873-4231-8a12-026f96560b4f restarted

cartopy version: 0.13.1 shapely version: 1.5.9 jupyter: 1.0.0

hdail avatar Mar 16 '16 03:03 hdail

I've gotten this to work now after upgrading to conda 4.0.4 and then doing a conda update --all. I'm now at:

cartopy: 0.13.1 shapely: 1.5.13 jupyter 1.0.0 py27_1 http://repo.continuum.io/pkgs/free/osx-64/jupyter-1.0.0-py27_1.tar.bz2 jupyter-client 4.2.1 jupyter-console 4.1.1 jupyter-core 4.1.0 jupyter_client 4.2.1 py27_0 defaults jupyter_console 4.1.1 py27_0 defaults jupyter_core 4.1.0 py27_0 defaults

hdail avatar Mar 16 '16 04:03 hdail

I tried updating Cartopy/Shapely/Jupyter/Conda for several times, nothing work. However, as soon as I removed the geos intalled via Homebrew, Cartopy works again. So it's all related to the version of GEOS. Earlier, I had issues with using basemap and cartopy at the same time, since the cartopy and basemap installed through conda depend on different version of geos, I needed to downgrade geos to 3.3 to make basemap work.

fischcheng avatar Mar 17 '16 01:03 fischcheng

Thanks for all the useful information. I can confirm that the message:

Assertion failed: (0 != cs), function GEOSCoordSeq_getSize_r, file geos_ts_c.cpp, line 3612.

Relates to the version of GEOS that is installed. See also #651, #612 and #481. Whilst it makes no difference to how bad this is, the problem emanates from https://github.com/Toblerity/Shapely/issues/177 and has been patched in the Shapely available through the scitools and IOOS conda channels.

pelson avatar Mar 17 '16 09:03 pelson

My system: OSX 10.11.6 with xcode-7.3 and pyenv virtual environments I've installed Cartopy into pyenv virtualenv's python2.7.12 and python3.5.2 python3.5.2 fails currently. python2.7.12 works after installing PyQt5 from source (qgis is a python2.7.12 virtualenv created from pyenv virtualenv python2.7.12 qgis)

    $ pyenv qgis
    (qgis) $ cd sip-4.18.1/
    (qgis) $ python configure.py
    (qgis) $ make
    (qgis) $ make install
    (qgis) $ cd PyQt5_gpl-5.7/
    (qgis) $ python configure.py --qmake=/usr/local/Cellar/qt5/5.7.0/bin/qmake \
                                 --sip=../../sip/sip-4.18.1/sipgen/sip \
                                 --sip-incdir=../../sip/sip-4.18.1/siplib
    (qgis) $ make
    (qgis) $ make install

Checked against:

    $ pyenv activate qgis
    (qgis) $ python
    >>> import cartopy.crs as ccrs
    >>> import matplotlib.pyplot as plt

    >>> ax = plt.axes(projection=ccrs.PlateCarree())
    >>> ax.coastlines()

    >>> plt.show()

I don't have the chance to check if installing PyQt5 from source for the python3 environment will cure the Assertion failed (0 != cs) error I am getting when attempting to run the same in python3. I'm also uncertain if PyQt5 affects this in any way or if it is just coincidental.

keevee09 avatar Oct 30 '16 08:10 keevee09

HI:

I think I have a related problem...

(py3.4) $ pip install cartopy
Requirement already satisfied: cartopy in ...python_virtualenvs/py3.4/lib/python3.4/site-packages
Requirement already satisfied: numpy>=1.6 in .../python_virtualenvs/py3.4/lib/python3.4/site-packages (from cartopy)
Requirement already satisfied: shapely>=1.5.6 in .../python_virtualenvs/py3.4/lib/python3.4/site-packages (from cartopy)
Requirement already satisfied: pyshp>=1.1.4 in .../python_virtualenvs/py3.4/lib/python3.4/site-packages (from cartopy)
Requirement already satisfied: six>=1.3.0 in .../python_virtualenvs/py3.4/lib/python3.4/site-packages (from cartopy)
Requirement already satisfied: setuptools>=0.7.2 in .../python_virtualenvs/py3.4/lib/python3.4/site-packages (from cartopy)
Requirement already satisfied: packaging>=16.8 in .../python_virtualenvs/py3.4/lib/python3.4/site-packages (from setuptools>=0.7.2->cartopy)
Requirement already satisfied: appdirs>=1.4.0 in .../python_virtualenvs/py3.4/lib/python3.4/site-packages (from setuptools>=0.7.2->cartopy)
Requirement already satisfied: pyparsing in .../python_virtualenvs/py3.4/lib/python3.4/site-packages (from packaging>=16.8->setuptools>=0.7.2->cartopy)
(py3.4) $ ipython
Python 3.4.3 (default, May 27 2016, 11:32:08)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.




In [1]: import cartopy
Segmentation fault (core dumped)  # <<<< Just kills ipython !!!!!



(py3.4) $ pip list | grep -i  cartopy
Cartopy (0.15.0)

guziy avatar Apr 09 '17 17:04 guziy

Actually, reinstalling the latest version of GEOS and using it to reinstall cartopy helped in my case.

Cheers

guziy avatar Apr 09 '17 21:04 guziy

I'm having the same issue after a clean install of cartopy in a python 3.5 virtualenv using pip install cartopy. I have a homebrew-installed geos 3.6.1 on my path. Currently starting to debug...

screen shot 2017-06-12 at 3 17 17 am

This also happens when pip installing from the master branch.

davenquinn avatar Jun 12 '17 10:06 davenquinn

I had the same issue, and it came down to the version of GEOS. I noticed that there was a conflict when install both Basemap and Cartopy through conda under Python3. So I ended up setting up two separate environments one for Basemap and the other for Cartopy.

On Mon, Jun 12, 2017 at 6:25 AM, Daven Quinn [email protected] wrote:

I'm having the same issue after a clean install of cartopy in a python 3.5 virtualenv using pip install cartopy. I have a homebrew-installed geos 3.6.1 on my path. Currently starting to debug...

[image: screen shot 2017-06-12 at 3 17 17 am] https://user-images.githubusercontent.com/1537910/27029557-b08060a0-4f1d-11e7-8815-27b7774ea4e4.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SciTools/cartopy/issues/738#issuecomment-307750718, or mute the thread https://github.com/notifications/unsubscribe-auth/AHY3x2SxO36Wk7W-3MwM3UUlaqpWaJShks5sDRI3gaJpZM4HxL3A .

fischcheng avatar Jun 12 '17 12:06 fischcheng

I don't have basemap installed. Does this mean that I can't have a newer (3.6) geos linked on my system, or somehow have to dig up an older version?

davenquinn avatar Jun 12 '17 17:06 davenquinn

Update: I fixed this; for me it was caused by "DLL hell" as referenced by @sgillies in #805 and Toblerity/Shapely#416. Basically, shapely was built as a wheel with an internal GEOS (or it was just built against an older GEOS I had installed, not sure) and the two versions conflict. The fix was to reinstall both shapely and cartopy using

pip install shapely cartopy --no-binary shapely --no-binary cartopy

There might be a better shorthand, I'm not sure. I'd urge the contributors to move forward with #805 in any way possible, but it looks like fixes are being discussed.

davenquinn avatar Jun 12 '17 20:06 davenquinn

pip install shapely cartopy --no-binary shapely --no-binary cartopy worked for me on osx 10.13.1

JeffLutzenberger avatar Nov 23 '17 01:11 JeffLutzenberger

It worked. Thank you.

  • If shapely and cartopy was already installed, remove it before re-install without binary.

xhiroga avatar Dec 10 '17 07:12 xhiroga

pip install shapely cartopy --no-binary shapely --no-binary cartopy worked for me too on linux mint 17.2 with python 3.

GGurtner avatar Dec 15 '17 15:12 GGurtner

It worked for me with mac. Thanks. pip install shapely cartopy --no-binary shapely --no-binary cartopy

leeliang avatar Dec 22 '17 07:12 leeliang

When using pipenv, I had to use

pipenv run pip install shapely cartopy --no-binary shapely --no-binary cartopy

philngo avatar Jan 26 '18 17:01 philngo

Following the tips here: #2359 helped me solve this in Jupyter Lab! Thanks @takluyver

j-la-haye avatar Jun 24 '18 11:06 j-la-haye

Just an update to keep things clear: this is still operative with the latest Shapely and Cartopy; the fix I referenced above still works. Was puzzled about this on a new computer...

davenquinn avatar Sep 17 '18 08:09 davenquinn

same problem, it´s works uninstall shapely and install again. i update all package too. i´m using python 3

thanks.

patsotoe avatar Jan 23 '19 15:01 patsotoe

Had same problem with Spyder on OSX, finally worked by uninstalling and and installing again using pip install shapely cartopy --no-binary shapely --no-binary cartopy

Thanks!

carocamargo avatar Mar 15 '19 16:03 carocamargo

I had same issue, reinstalling fixes it. As mentioned by others I had to uninstall and install both packages again.

yrevar avatar Mar 22 '19 18:03 yrevar

I had a related issue, namely, when calling ax.coastlines() the kernel crashed. I solved it by upgrading python 2.7.6 to 2.7.15

rvalenzuelar avatar Apr 26 '19 18:04 rvalenzuelar

I'm hugely enjoying Cartopy!

Unfortunately, I think I'm getting the same problem as described in this thread (although I'm on Ubuntu not MacOS; and Jupyter doesn't print any useful errors to the terminal before the kernel crash):

The following code crashes the kernel in jupyter lab or jupyter notebook:

import cartopy.crs as ccrs
osgb = ccrs.OSGB()

# The crash occurs after this line:
osgb

This same code doesn't crash in IPython terminal or Python.

I'm using Python 3.7.3 and Cartopy 0.17.0

I've tried several versions of proj, including proj 6.2.0 (the latest version at the time of writing).

I'll try the fixes reported above...

JackKelly avatar Sep 11 '19 22:09 JackKelly

Update to my post above:

After several hours of trying to get this to work, I finally managed to get this to work with:

sudo apt install libgeos-dev
conda create --name cartopy_test scipy matplotlib notebook pandas pyproj numpy cython shapely
conda activate cartopy_test
pip install git+https://github.com/SciTools/cartopy.git --no-binary cartopy

# Then, if required, install packages which depend in cartopy, for example
conda install satpy

notebook no longer crashes when I run ccrs.OSGB(). Hurray!

I found it necessary to install cartopy from git (not v0.17.0 from pypi) because, if I try installing from pypi, I bump into issue #1288

It appears that it's now fine to install shapely using conda. That is, it's no longer necessary to do pip install shapely --no-binary shapely.

At the time of writing, the latest cartopy commit is 23e31dd

For reference, here are my platform details:

Output of pyproj.show_versions():

System:
    python: 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21)  [GCC 7.3.0]
executable: /home/jack/miniconda3/envs/test3/bin/python
   machine: Linux-5.0.0-27-generic-x86_64-with-debian-buster-sid

PROJ:
      PROJ: 6.1.1
  data dir: /home/jack/miniconda3/envs/test3/share/proj

Python deps:
    pyproj: 2.3.1
       pip: 19.2.3
setuptools: 41.2.0
    Cython: 0.29.13

Output of conda list:

# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
attrs                     19.1.0                     py_0    conda-forge
backcall                  0.1.0                      py_0    conda-forge
bleach                    3.1.0                      py_0    conda-forge
bzip2                     1.0.8                h516909a_1    conda-forge
ca-certificates           2019.9.11            hecc5488_0    conda-forge
cartopy                   0.17.1.dev172-           pypi_0    pypi
certifi                   2019.9.11                py37_0    conda-forge
cycler                    0.10.0                     py_1    conda-forge
cython                    0.29.13          py37he1b5a44_0    conda-forge
dbus                      1.13.6               he372182_0    conda-forge
decorator                 4.4.0                      py_0    conda-forge
defusedxml                0.5.0                      py_1    conda-forge
entrypoints               0.3                   py37_1000    conda-forge
expat                     2.2.5             he1b5a44_1003    conda-forge
fontconfig                2.13.1            h86ecdb6_1001    conda-forge
freetype                  2.10.0               he983fc9_1    conda-forge
gettext                   0.19.8.1          hc5be6a0_1002    conda-forge
glib                      2.58.3            h6f030ca_1002    conda-forge
gst-plugins-base          1.14.5               h0935bb2_0    conda-forge
gstreamer                 1.14.5               h36ae1b5_0    conda-forge
icu                       64.2                 he1b5a44_1    conda-forge
ipykernel                 5.1.2            py37h5ca1d4c_0    conda-forge
ipython                   7.8.0            py37h5ca1d4c_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
jedi                      0.15.1                   py37_0    conda-forge
jinja2                    2.10.1                     py_0    conda-forge
jpeg                      9c                h14c3975_1001    conda-forge
jsonschema                3.0.2                    py37_0    conda-forge
jupyter_client            5.3.1                      py_0    conda-forge
jupyter_core              4.4.0                      py_0    conda-forge
kiwisolver                1.1.0            py37hc9558a2_0    conda-forge
libblas                   3.8.0               12_openblas    conda-forge
libcblas                  3.8.0               12_openblas    conda-forge
libffi                    3.2.1             he1b5a44_1006    conda-forge
libgcc-ng                 9.1.0                hdf63c60_0  
libgfortran-ng            7.3.0                hdf63c60_0  
libiconv                  1.15              h516909a_1005    conda-forge
liblapack                 3.8.0               12_openblas    conda-forge
libopenblas               0.3.7                h6e990d7_1    conda-forge
libpng                    1.6.37               hed695b0_0    conda-forge
libsodium                 1.0.17               h516909a_0    conda-forge
libstdcxx-ng              9.1.0                hdf63c60_0  
libuuid                   2.32.1            h14c3975_1000    conda-forge
libxcb                    1.13              h14c3975_1002    conda-forge
libxml2                   2.9.9                hee79883_5    conda-forge
markupsafe                1.1.1            py37h14c3975_0    conda-forge
matplotlib                3.1.1                    py37_1    conda-forge
matplotlib-base           3.1.1            py37he7580a8_1    conda-forge
mistune                   0.8.4           py37h14c3975_1000    conda-forge
nbconvert                 5.6.0                    py37_1    conda-forge
nbformat                  4.4.0                      py_1    conda-forge
ncurses                   6.1               hf484d3e_1002    conda-forge
notebook                  6.0.1                    py37_0    conda-forge
numpy                     1.17.2           py37h95a1406_0    conda-forge
openssl                   1.1.1c               h516909a_0    conda-forge
pandas                    0.25.1           py37hb3f55d8_0    conda-forge
pandoc                    2.7.3                         0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.5.1                      py_0    conda-forge
pcre                      8.41              hf484d3e_1003    conda-forge
pexpect                   4.7.0                    py37_0    conda-forge
pickleshare               0.7.5                 py37_1000    conda-forge
pip                       19.2.3                   py37_0    conda-forge
proj4                     6.1.1                hc80f0dc_1    conda-forge
prometheus_client         0.7.1                      py_0    conda-forge
prompt_toolkit            2.0.9                      py_0    conda-forge
pthread-stubs             0.4               h14c3975_1001    conda-forge
ptyprocess                0.6.0                   py_1001    conda-forge
pygments                  2.4.2                      py_0    conda-forge
pyparsing                 2.4.2                      py_0    conda-forge
pyproj                    2.3.1            py37h2fd02e8_0    conda-forge
pyqt                      5.9.2            py37hcca6a23_4    conda-forge
pyrsistent                0.15.4           py37h516909a_0    conda-forge
pyshp                     2.1.0                    pypi_0    pypi
python                    3.7.3                h33d41f4_1    conda-forge
python-dateutil           2.8.0                      py_0    conda-forge
pytz                      2019.2                     py_0    conda-forge
pyzmq                     18.1.0           py37h1768529_0    conda-forge
qt                        5.9.7                h0c104cb_3    conda-forge
readline                  8.0                  hf8c457e_0    conda-forge
scipy                     1.3.1            py37h921218d_2    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                41.2.0                   py37_0    conda-forge
shapely                   1.6.4.post2              pypi_0    pypi
sip                       4.19.8          py37hf484d3e_1000    conda-forge
six                       1.12.0                py37_1000    conda-forge
sqlite                    3.29.0               hcee41ef_1    conda-forge
terminado                 0.8.2                    py37_0    conda-forge
testpath                  0.4.2                   py_1001    conda-forge
tk                        8.6.9             hed695b0_1003    conda-forge
tornado                   6.0.3            py37h516909a_0    conda-forge
traitlets                 4.3.2                 py37_1000    conda-forge
wcwidth                   0.1.7                      py_1    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.33.6                   py37_0    conda-forge
xorg-libxau               1.0.9                h14c3975_0    conda-forge
xorg-libxdmcp             1.1.3                h516909a_0    conda-forge
xz                        5.2.4             h14c3975_1001    conda-forge
zeromq                    4.3.2                he1b5a44_2    conda-forge
zlib                      1.2.11            h516909a_1006    conda-forge

JackKelly avatar Sep 16 '19 10:09 JackKelly

Using Python 3.6.9 on Ubuntu 18.04 LTS, without Conda, it still seems necessary to install both shapely and cartopy like pip3 install shapely cartopy --no-binary shapely --no-binary cartopy per @davenquinn

temcdrm avatar Sep 18 '20 00:09 temcdrm

This comment is for everybody who tries to install cartopy without the use of conda, i.e. using pip on Ubuntu Server 22.04 LTS or Ubuntu 20.04 LTS (both tested). In the following you can find all steps that were necessary to get it running:

export N_CPU_CORES=$(nproc)
sudo apt install python3-pip -y
pip install pyshp

sudo apt install libtiff-dev, libcurl4-openssl-dev

# install geos
git clone https://github.com/libgeos/geos.git
cd geos
mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release ..
make -j${N_CPU_CORES}
sudo make install -j${N_CPU_CORES}
cd ../..

# build sqlite binary + install headers 
git clone https://github.com/sqlite/sqlite
cd sqlite
mkdir bld
cd bld/
../configure 
make -j${N_CPU_CORES}
sudo make install -j${N_CPU_CORES}
cd ../..

# build and install Proj (I used 9.0.1) 
git clone https://github.com/OSGeo/PROJ.git
cd PROJ
mkdir build && cd build/
cmake ..
cmake --build . -j${N_CPU_CORES}
make -j20
sudo make install -j${N_CPU_CORES}
cd ../..

# it seems redundant installing libgeos-dev via apt after build&install from src, however after I did that and reinstalled cartopy, it took care of the Notebook crashes 
sudo apt install libgeos-dev
pip install git+https://github.com/SciTools/cartopy.git --no-binary cartopy

I guess since this hasn't been solved since years it's not far-fetched to suggest adding a note to the installation document, for the possible peculiarities one faces when attempting to install cartopy while avoiding conda. ;)

wijjj avatar Jul 16 '22 19:07 wijjj

I have just discovered a not so ugly work-around for the issue which effects the COASTLINE feature in the pip installation of cartopy, e.g. the ax.coastlines() The trick I found to work was to use the LAND feature instead, minimum reproducable example:

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

ax1 = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND, edgecolor='black', facecolor="none", linewidth=1)

I found that this solved the issue when running a notebook on Colab. (I also had to manually set the zorder to make sure it was above my data layer)

EddyCMWF avatar Mar 08 '23 09:03 EddyCMWF

We have just released v0.22 which should help with the compatibility between packages and installation much easier. Please open a new issue if you are still having problems.

greglucas avatar Aug 05 '23 02:08 greglucas