3

On Google Colab I'm getting an error when trying to import GeoJSON from IPython.display:

enter image description here

Any help on how to properly import it would be appreciated.

Angel Cloudwalker
  • 2,015
  • 5
  • 32
  • 54
  • Here's another [thread](https://stackoverflow.com/questions/45558954/geojson-in-ipython-display-cannot-be-imported-in-jupyter-notebook) where the same issue was encountered about 3 years ago. It appears to have been fixed in this [PR](https://github.com/ipython/ipython/pull/10253). I have also tested the same locally and it works perfectly. Try updating your IPython. – InsertCheesyLine Sep 22 '20 at 07:37

3 Answers3

3

I found the issue to be caused by your Collab runtime having an older version of IPython installed.

pip freeze

Output

ipython==5.5.0
ipython-genutils==0.2.0
ipython-sql==0.3.9
ipywidgets==7.5.1

Since the collab was created sometime ago

Updating the module fixed the issue for me

pip install -U IPython 

After which you can restart your runtime and the changes should be reflected

pip freeze

Output

ipython==7.16.1
ipython-genutils==0.2.0
ipython-sql==0.3.9
InsertCheesyLine
  • 1,112
  • 2
  • 11
  • 19
  • Thanks for sharing this, since I'm using Google Colab though I didn't mark as answer since colab needs ! before pip commands - didn't want to confuse people trying this answer. – Angel Cloudwalker Sep 22 '20 at 15:18
2

Exactly how to execute in Google Colab:

  1. import IPython
  2. Update IPython
  3. Now able to from IPython.display import GeoJson

enter image description here

Angel Cloudwalker
  • 2,015
  • 5
  • 32
  • 54
0

Google Colaboratory has an older version of IPython installed (v5.5.0 as of the time I'm writing this). The best way to fix this is to include the following line in the Colab notebook before your import statements:

!pip3 install --upgrade IPython

This should fix it for you!

JaonHax
  • 336
  • 1
  • 8