geemap: Map does not display in jupyterlab, "Loading widget..." or "Error displaying widget: model not found"

I am betting this is rather an ipyleaflet plus jupyter-lab issue, but I open this ticket hoping to provide workarounds/fixes for other users as this may be one of the first experience (i.e. impression) for newcomers.

  • geemap version: 0.6.10 from conda-forge
  • Python version: 3.8.2
  • Operating System: Linux 4.19.0-8-amd64 #1 SMP Debian 4.19.98-1+deb10u1 (2020-04-27) x86_64 GNU/Linux

Description

example notebook 01_geemap_intro Map does not display in the cell output in jupyterlab, instead “Loading widget…” or “Error displaying widget: model not found” Display works if accessed/run from jupyter-notebook however. I think I previously similar symptoms with upyleaflet

What I Did

Updated an existing conda env which had ipyleaflet working. conda update -c conda-forge python=3.8, then conda install -c conda-forge geemap

jupyter-lab opened and requested a rebuild of the extensions:

[W 12:30:43.793 LabApp] Build recommended
[W 12:30:43.793 LabApp] jupyter-leaflet needs to be included in build
[W 12:30:43.793 LabApp] @jupyter-widgets/jupyterlab-manager needs to be included in build

Once done, Map resulted in “Loading widget…” , but I think this was because I should have restarted jupyter-lab. Using the script

#!/bin/bash
source ${HOME}/anaconda3/bin/activate sv
jupyter-nbextension list
cd ${HOME}/src/github/geemap
jupyter-lab --browser=/usr/bin/google-chrome
Known nbextensions:
  config dir: /home/xxxyyy/anaconda3/envs/sv/etc/jupyter/nbconfig
    notebook section
      bqplot/extension  enabled 
      - Validating: OK
      jupyter-leaflet/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
  config dir: /etc/jupyter/nbconfig
    notebook section
      jupyter-js-widgets/extension  enabled 
      - Validating: OK

but upon re-execution of the notebook 01_geemap_intro Map then leads to “Error displaying widget: model not found”

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (12 by maintainers)

Most upvoted comments

@jmp75 Thanks for the troubleshooting. For users who are having difficulty displaying the map, you can enable the ipyleaflet extension using the following two commands. Then you can type jupyter nbextension list to see whether the extension has been enabled successfully.

jupyter nbextension install --py --symlink --sys-prefix ipyleaflet
jupyter nbextension enable --py --sys-prefix ipyleaflet

I was almost able to follow the solution from @nanodan nanodan to get geemap to work on Jupyter Lab but I needed to modify it slightly.

I downloaded GDAL-3.2.3-cp38-cp38-win_amd64.whl and rasterio-1.2.3-cp38-cp38-win_amd64.whl from https://www.lfd.uci.edu/~gohlke/pythonlibs/ and replaced those file names in the .bat file.

I’m using conda so I also ran: conda create geelab python=3.8 conda activate geelab conda install mamba -c conda-forge

pipenv install pipenv run pip install GDAL-3.2.3-cp38-cp38-win_amd64.whl --force-reinstall pipenv run pip install rasterio-1.2.3-cp38-cp38-win_amd64.whl --force-reinstall pipenv run mamba install -c conda-forge nodejs pipenv run pip install -r requirements_fulllist.txt pipenv run jupyter labextension uninstall ipyevents pipenv run jupyter lab build pipenv run mamba install -c conda-forge pywin32

then you can start Jupyter Lab with geemap by running pipenv run jupyter lab

Once you have Jupyter Lab running try running: import geemap m = geemap.Map() m

You will get an error that says something like: FileNotFoundError: Could not find module ‘c:\users\me.virtualenvs\me-ym2aifmq\Library\bin\geos_c.dll’ (or one of its dependencies). Try using the full path with constructor syntax.

Instead of “me” in the folder names it will be your user name.

Then you have to create the “Library” and “bin” folder where they are expected (from the error), and copy the geos_c.dll from the “me-ym2aifmq\Lib\site-packages\osgeo” folder to the bin folder you just created (I tried with the shapely provided geos_c.dll and it doesn’t work).

Now if you try running that cell in Jupyter Lab again it will display a map.

This is a very convoluted solution but it does so far seem to work. Also I’m not sure how great of a practice it is to be using conda with pipenv.

Anyways, it’d be great to not have to do all this. But since @nanodan had got it working and I had to do some more stuff to get it to work on my end I thought I’d share my solution. Any idea of when there will be a better solution?

@robmarkcole This is an ipyleaflet problem rather than geemap. Check https://github.com/jupyter-widgets/ipyleaflet/issues/739 to see if it helps. You can also check out the geemap docker images at https://geemap.org/installation/#use-docker

Only way I could get this working was to fork it, modify requirements file to remove ipyevents, set ipyleaflet to 0.13.6, install ipyevents after fixed dependencies… then uninstall ipyevents from jupyterlab, while leaving it as a package, and rebuild jupyterlab, while version-fixing a whole bunch of dependencies.

.bat file

pipenv install
pipenv run pip install GDAL-3.2.1-cp39-cp39-win_amd64.whl
pipenv run pip install rasterio-1.2.0-cp39-cp39-win_amd64.whl
pipenv run pip install -r requirements_fulllist.txt
pipenv run jupyter labextension uninstall ipyevents
pipenv run jupyter lab build

where requirements_fulllist.txt is:

git+https://github.com/nanodan/geemap
affine==2.3.0
anyio==2.0.2
argon2-cffi==20.1.0
async-generator==1.10
attrs==20.3.0
Babel==2.9.0
backcall==0.2.0
bleach==3.3.0
branca==0.4.2
certifi==2020.12.5
cffi==1.14.4
chardet==4.0.0
click==7.1.2
click-plugins==1.1.1
cligj==0.7.1
colorama==0.4.4
decorator==4.4.2
defusedxml==0.6.0
entrypoints==0.3
idna==2.10
ipykernel==5.4.3
ipyleaflet==0.13.6
ipython==7.20.0
ipython-genutils==0.2.0
ipywidgets==7.6.3
jedi==0.18.0
Jinja2==2.11.3
json5==0.9.5
jsonschema==3.2.0
jupyter-client==6.1.11
jupyter-core==4.7.1
jupyter-server==1.3.0
jupyterlab==3.0.7
jupyterlab-pygments==0.1.2
jupyterlab-server==2.2.0
jupyterlab-widgets==1.0.0
MarkupSafe==1.1.1
mistune==0.8.4
nbclassic==0.2.6
nbclient==0.5.1
nbconvert==6.0.7
nbformat==5.1.2
nest-asyncio==1.5.1
notebook==6.2.0
numpy==1.20.0
packaging==20.9
pandocfilters==1.4.3
parso==0.8.1
pickleshare==0.7.5
prometheus-client==0.9.0
prompt-toolkit==3.0.14
pycparser==2.20
Pygments==2.7.4
pyparsing==2.4.7
pyrsistent==0.17.3
python-dateutil==2.8.1
pytz==2021.1
pywin32==300
pywinpty==0.5.7
pyzmq==22.0.2
requests==2.25.1
Send2Trash==1.5.0
Shapely==1.7.1
six==1.15.0
sniffio==1.2.0
snuggs==1.4.7
terminado==0.9.2
testpath==0.4.4
tornado==6.1
traitlets==5.0.5
traittypes==0.2.1
urllib3==1.26.3
wcwidth==0.2.5
webencodings==0.5.1
widgetsnbextension==3.5.1
ipyevents

Hopefully this helps somebody.

A precision for jupyterlab users, widget registrations are not the same as for jupyter-notebook. To check which extension is registered you should use jupyter labextension list and expect an output like:

JupyterLab v2.0.0
Known labextensions:
   app dir: /home/xxxyyy/anaconda3/envs/sv/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
        bqplot v0.5.10  enabled  OK
        jupyter-leaflet v0.12.4  enabled  OK

Solution:

Reading ipyleaflet issue 504 I forced a reinstall of the jupyter-leaflet extension from the command line:

conda activate sv # or whatever you have named it
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-leaflet

jupyter-nbextension list has the same output as before, but now the notebook does display the widget as expected. One conclusion is that you should prefer the command line for installing extensions, rather the jupyter-lab triggered 'Build"

Hope this helps.