jupyter-widgets / ipyleaflet

A Jupyter - Leaflet.js bridge
https://ipyleaflet.readthedocs.io
MIT License
1.48k stars 363 forks source link

Using ipyleaflet with Amazon SageMaker Studio Lab - Error displaying widget: model not found #1034

Open giswqs opened 2 years ago

giswqs commented 2 years ago

Has anyone ever used ipyleaflet with Amazon SageMaker Studio Lab? I can't get it to work.

chrome_kcV1PStfHD

jasongrout commented 2 years ago

CC @jweill-aws

JasonWeill commented 2 years ago

Thanks for reporting this! I've informed the SageMaker Studio Lab team.

MicheleMonclova commented 2 years ago

Hi- try installing with a % instead of a !. See Studio Lab FAQ below.

Q: How can I install open-source Python packages?

To install Python packages, you can use ‘%pip install ’ or ‘%conda install ’ in any notebook. Please make sure to use this form (with ‘%’) instead of ‘!pip’ and ‘!conda.’ Using the ‘%’ ensures you are installing the packages in the correct path.

giswqs commented 2 years ago

I just uninstalled ipyeaflet and reinstalled using %conda install ipyleaflet -c conda-forge -y. Restarted the kernel and still got the same error. Is there a way to do a factory reset of my account so that I can start from scratch to install ipyleaflet?

image

JasonWeill commented 2 years ago

@giswqs There is no "reset" button in Studio Lab just yet. If you would like to reset your account, you can delete your account and register again. You will not have to wait for another approval as long as you use the same information when you register again.

jasongrout commented 2 years ago

I just uninstalled ipyeaflet and reinstalled using %conda install ipyleaflet -c conda-forge -y. Restarted the kernel and still got the same error. Is there a way to do a factory reset of my account so that I can start from scratch to install ipyleaflet?

I'll just point out that your labextension list indicates it installed ipywidgets 8, and ipyleaflet is not yet compatible with ipywidgets 8. That may be why it had an error displaying. We're working on ipywidgets 8 compatibility over in #968, and it should be coming soon.

raybellwaves commented 1 year ago

@jasongrout where did you see ipywidgets 8? I only see from https://user-images.githubusercontent.com/5016453/185829006-bc1d5b25-03ad-4b32-8270-4a063547b9d1.png:

JupyterLab v3.2.4 /home/.../labextensions ipytree v0.2.1 ipyevents v1.9.0 bqplot v0.5.32 jupyterlab-plotly v5.9.0 jupyterlab_pygments v0.2.2 jupyter-leaflet v0.17.0 @jupyter-widgets/jupyterlab-manager v5.0.2 @here/map-widget-for-jupyter v1.1.3

jasongrout commented 1 year ago

@jupyter-widgets/jupyterlab-manager v5.0.2

This is the version of the widgets manager that comes with ipywidgets 8.

FYI, ipyleaflet now supports ipywidgets 8.

giswqs commented 1 year ago

@MicheleMonclova @JasonWeill I tested ipyleaflet on three SageMaker platforms, including SageMaker, SageMaker EC2 notebook instance, and SageMaker Studio Lab. Unfortunately, none of them work. Any advice?

suredream commented 3 days ago

Different error in 2024. ipyleaflet-0.17.4, jupyterlab-4.1.6.

image

maartenbreddels commented 3 days ago

For solara, we did some special checking if the jupyter server actually serves the extension:

cell 1

%pip install solara ipyleaflet

cell 2:

import solara
# a bug in solara, so we monkey patch it
solara._using_solara_server = lambda: False

# pass in updated module names (next release of solara we should also fix this)
libraries_extra = [
    {"python": "bqplot", "classic": "bqplot/extension", "lab": "bqplot"},
    {"python": "ipyvolume", "classic": "ipyvolume/extension", "lab": "ipyvolume"},
    {"python": "ipywebrtc", "classic": "jupyter-webrtc", "lab": "jupyter-webrtc"},
    {"python": "ipyleaflet", "classic": "ipyleaflet/extension", "lab": "jupyter-leaflet"},
]

solara.checks.check_jupyter(silent=False, force=True, extra=True, libraries_extra=libraries_extra)

It should look like this:

image

After running

!/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python3.10 -m pip install ipyvuetify ipyvue bqplot ipyvolume ipywebrtc ipyleaflet

And a page refresh, you should see:

image

Now ipyleaflet works!

Let me know if that solves your problems.

giswqs commented 3 days ago

I tried it on SageMaker Studio Lab. I can see that now the extentions have been installed successfully, but ipyleaflet still does not work. Any advice?

image

maartenbreddels commented 3 days ago

What do you see in the js console?

giswqs commented 3 days ago

image

maartenbreddels commented 3 days ago

With normal sagemaker (Jupyter Lab), I have it working

image

The _JUPYTERLAB variable that I print out in the js console (which contains _JUPYTERLAB["jupyter-leaflet"]), is what we use to determine if it is installed as an extensions in the frontend or not.

I'm out of ideas now, because it should just work. I asked for a Sagemager Studio Lab account, maybe I can debug it if I get it.

giswqs commented 3 days ago

@maartenbreddels You are a life saver! I can confirm that it works with the normal SageMaker now. Not sure what's the issue with the Studio Lab, but at least the normal SageMaker is working now. This is exciting!

image

giswqs commented 3 days ago

And MapLibre also works now!

image

maartenbreddels commented 3 days ago

Great. There are quite a few gems in solara :)

I'll fix solara, because it should do this check always when importing. It would be great if all ipywidget libraries would be checked this way.

giswqs commented 3 days ago

That would be nice! This have been a long standing for over two years. So happy to see that we finally have a solution. Thank you very much.

maartenbreddels commented 2 days ago

Ok, I got it working on Studio Lab as well.

Include this patch:

import sys
import os
def getcmdline(pid):
    # for linux
    if sys.platform == "linux":
        # if /proc/{pid}/exe exists, follow the symlink
        if os.path.exists(f"/proc/{pid}/exe"):
            return os.readlink(f"/proc/{pid}/exe")
        with open(f"/proc/{pid}/cmdline", "rb") as f:
            return f.read().split(b"\00")[0].decode("utf-8")
    elif sys.platform == "darwin":
        return subprocess.check_output(["ps", "-o", "command=", "-p", str(pid)]).split(b"\n")[0].split(b" ")[0].decode("utf-8")
    elif sys.platform == "win32":
        return subprocess.check_output(["wmic", "process", "get", "commandline", "/format:list"]).split(b"\n")[0].split(b" ")[0].decode("utf-8")
    else:
        raise ValueError(f"Unsupported platform: {sys.platform}")
solara.checks.getcmdline = getcmdline

After that, the install command was correct, and executed in a cell

!/home/studio-lab-user/.conda/envs/studiolab/bin/python3.9 -m pip install ipyvuetify ipyvue bqplot ipyvolume ipywebrtc ipyleaflet

After that, ipyleaflet worked for me

giswqs commented 1 day ago

SageMaker Studio Lab still does not work for me.

image

image

giswqs commented 1 day ago

Here are the steps I used to fix the issue on the normal SageMaker. It works like a charm.

  1. Create a new notebook instance and select the appropriate hardware (e.g., ml.t3.medium)
  2. Open the terminal
  3. Install packages: mamba install -c conda-forge leafmap solara
  4. Create a new notebook using the Python 3 (ipykernel)
  5. Run this code below below. It may show that the extensions are NOT installed at the server
    
    import solara
    # a bug in solara, so we monkey patch it
    solara._using_solara_server = lambda: False

pass in updated module names (next release of solara we should also fix this)

libraries_extra = [ {"python": "bqplot", "classic": "bqplot/extension", "lab": "bqplot"}, {"python": "ipyvolume", "classic": "ipyvolume/extension", "lab": "ipyvolume"}, {"python": "ipywebrtc", "classic": "jupyter-webrtc", "lab": "jupyter-webrtc"}, {"python": "ipyleaflet", "classic": "ipyleaflet/extension", "lab": "jupyter-leaflet"}, ]

solara.checks.check_jupyter(silent=False, force=True, extra=True, libraries_extra=libraries_extra)

6. Run the following command to install extensions
```bash
!/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python3.10 -m pip install ipyvuetify ipyvue bqplot ipyvolume ipywebrtc ipyleaflet anywidget
  1. Restart the kernel and refresh the browser page. Then run the following code block again. It should now show that the extensions have been installed at the server
    
    import solara
    # a bug in solara, so we monkey patch it
    solara._using_solara_server = lambda: False

pass in updated module names (next release of solara we should also fix this)

libraries_extra = [ {"python": "bqplot", "classic": "bqplot/extension", "lab": "bqplot"}, {"python": "ipyvolume", "classic": "ipyvolume/extension", "lab": "ipyvolume"}, {"python": "ipywebrtc", "classic": "jupyter-webrtc", "lab": "jupyter-webrtc"}, {"python": "ipyleaflet", "classic": "ipyleaflet/extension", "lab": "jupyter-leaflet"}, ]

solara.checks.check_jupyter(silent=False, force=True, extra=True, libraries_extra=libraries_extra)

8. Try leafmap with ipyleaflet
```python
import leafmap
leafmap.Map()
  1. Try leafmap with maplibre
    import leafmap.maplibregl as leafmap
    leafmap.Map()
suredream commented 23 hours ago

I did the same thing early this week and got it works. The step #6 and #7 are the keys.

Here are the steps I used to fix the issue on the normal SageMaker. It works like a charm.

  1. Create a new notebook instance and select the appropriate hardware (e.g., ml.t3.medium)
  2. Open the terminal
  3. Install packages: mamba install -c conda-forge leafmap solara
  4. Create a new notebook using the Python 3 (ipykernel)
  5. Run this code below below. It may show that the extensions are NOT installed at the server
import solara
# a bug in solara, so we monkey patch it
solara._using_solara_server = lambda: False

# pass in updated module names (next release of solara we should also fix this)
libraries_extra = [
    {"python": "bqplot", "classic": "bqplot/extension", "lab": "bqplot"},
    {"python": "ipyvolume", "classic": "ipyvolume/extension", "lab": "ipyvolume"},
    {"python": "ipywebrtc", "classic": "jupyter-webrtc", "lab": "jupyter-webrtc"},
    {"python": "ipyleaflet", "classic": "ipyleaflet/extension", "lab": "jupyter-leaflet"},
]

solara.checks.check_jupyter(silent=False, force=True, extra=True, libraries_extra=libraries_extra)
  1. Run the following command to install extensions
!/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python3.10 -m pip install ipyvuetify ipyvue bqplot ipyvolume ipywebrtc ipyleaflet anywidget
  1. Restart the kernel and refresh the browser page. Then run the following code block again. It should now show that the extensions have been installed at the server
import solara
# a bug in solara, so we monkey patch it
solara._using_solara_server = lambda: False

# pass in updated module names (next release of solara we should also fix this)
libraries_extra = [
    {"python": "bqplot", "classic": "bqplot/extension", "lab": "bqplot"},
    {"python": "ipyvolume", "classic": "ipyvolume/extension", "lab": "ipyvolume"},
    {"python": "ipywebrtc", "classic": "jupyter-webrtc", "lab": "jupyter-webrtc"},
    {"python": "ipyleaflet", "classic": "ipyleaflet/extension", "lab": "jupyter-leaflet"},
]

solara.checks.check_jupyter(silent=False, force=True, extra=True, libraries_extra=libraries_extra)
  1. Try leafmap with ipyleaflet
import leafmap
leafmap.Map()
  1. Try leafmap with maplibre
import leafmap.maplibregl as leafmap
leafmap.Map()