Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
giswqs opened this issue Aug 2, 2022 · 23 comments

Comments

@giswqs
Copy link
Contributor

giswqs commented Aug 2, 2022

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

chrome_kcV1PStfHD

@jasongrout
Copy link
Member

CC @jweill-aws

@JasonWeill
Copy link

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

@MicheleMonclova
Copy link

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
Copy link
Contributor Author

giswqs commented Aug 22, 2022

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
Copy link

@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
Copy link
Member

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
Copy link

raybellwaves commented Oct 19, 2022

@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
Copy link
Member

@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
Copy link
Contributor Author

giswqs commented Feb 7, 2023

@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
Copy link

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

image

@maartenbreddels
Copy link
Member

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
Copy link
Contributor Author

giswqs commented Aug 28, 2024

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
Copy link
Member

What do you see in the js console?

@giswqs
Copy link
Contributor Author

giswqs commented Aug 28, 2024

image

@maartenbreddels
Copy link
Member

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
Copy link
Contributor Author

giswqs commented Aug 28, 2024

@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
Copy link
Contributor Author

giswqs commented Aug 28, 2024

And MapLibre also works now!

image

@maartenbreddels
Copy link
Member

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
Copy link
Contributor Author

giswqs commented Aug 28, 2024

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 added a commit to widgetti/solara that referenced this issue Aug 28, 2024
Found out in jupyter-widgets/ipyleaflet#1034
that we think the server is running because solara.server is imported.

For this reason, we do not check any of the widget extensions.
@maartenbreddels
Copy link
Member

maartenbreddels commented Aug 29, 2024

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

maartenbreddels added a commit to widgetti/solara that referenced this issue Aug 29, 2024
Found out in jupyter-widgets/ipyleaflet#1034
that we think the server is running because solara.server is imported.

For this reason, we do not check any of the widget extensions.
@giswqs
Copy link
Contributor Author

giswqs commented Aug 30, 2024

SageMaker Studio Lab still does not work for me.

image

image

@giswqs
Copy link
Contributor Author

giswqs commented Aug 30, 2024

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()

@suredream
Copy link

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants