Error and kernel dies with shapely/geos inside Jupyter notebook

I have a Python 2.7 script (code below) that scrapes data from a table on the web and draws a map. It runs fine from the command line using

$ python

When I run the identical script from inside a Jupyter notebook, the kernel dies (and apparently restarts) and I get this error:

ERROR:shapely.geos:Geometry must be a Point or LineString ERROR:shapely.geos:Geometry must be a Point or LineString

I am on a MacBook Pro using OS X 10.9.5. My Python environment is the free Anaconda distribution.

I am new to cartopy/shapely/geos.


import re import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import as ccrs import as shpreader import requests from bs4 import BeautifulSoup, Tag # scrape bear sightings data BEAR_SIGHTINGS_URL = '' r = requests.get(BEAR_SIGHTINGS_URL) soup = BeautifulSoup(r.content, "html.parser") # extract time period covered by the bear sightings date = 'd{1,2}/d{1,2}/d{4}' pattern = date + ' to ' + date result =, str(soup)) # create dict of all 169 towns in Conn. towns = {} with open("towns.d") as t: for line in t: key = line.strip() towns[key] = 0 # extract sightings data and enter in towns dict. # towns without any sightings are not listed on the state web page # help from: # beautifulsoup-return-next-sibling-after-using-findalltext bear_sightings = {} for t in soup.find_all(width="75%", valign="middle", align="left"): twn = t.find('font').string.strip() for item in t.next_siblings: if isinstance(item, Tag): num = item.find('font').string.strip() towns[twn] = int(num) # draw the map and colorbar fig = plt.figure(figsize=(6, 6)) ax1 = fig.add_axes([0, 0, 1, 1], frameon=False, projection=ccrs.Mercator()) ax1.set_extent([-74, -71.5, 40.5, 42.25], ccrs.Geodetic()) ax1.outline_patch.set_visible(False) ax2 = fig.add_axes([0.4, 0.33, 0.45, 0.03]) cmap = bounds = np.linspace(0, 500, 11) norm = mpl.colors.BoundaryNorm(bounds, cmap.N) shape_file_name = 'townct_37800_0000_1984_s24_ctdep_1_shp/WGS84/townct_37800_0000_1984_s24_ctdep_1_shp_wgs84.shp' towns_shp = shpreader.Reader(shape_file_name) for this_town in towns_shp.records(): raw_face_color = towns[this_town.attributes['TOWN']] ax1.add_geometries(this_town.geometry, ccrs.PlateCarree(), facecolor=cmap(raw_face_color)) cb = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, norm=norm, ticks=bounds, spacing="uniform", orientation="horizontal") cb.set_label('Number of bear sightings') sup_title_string = 'test2 Black bear sightings in Connecticut
 %s' % fig.suptitle(sup_title_string,fontsize=18) plt.savefig('bears.png">shapely geos anaconda cartopy jupyter-notebook

Watch the video: how to fix anaconda navigator problem in win 10 2018 (October 2021).