Jupyter Notebook中Leaflet报JavaScript错误无法加载,求解决方案
解决jupyter-leaflet无法加载LeafletMapModel的JavaScript错误
问题重现
运行segment-geospatial测试脚本时,昨日可正常生成地图,今日执行单元格后弹出JavaScript错误:
[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'LeafletMapModel' from module 'jupyter-leaflet'
makeError@http://localhost:8888/static/components/requirejs/require.js:168:26
onScriptError@http://localhost:8888/static/components/requirejs/require.js:1735:45
测试脚本代码:
#Import necessary packages import samgeo import os import torch import leafmap from samgeo import SamGeo, tms_to_geotiff m = leafmap.Map(center=[29.676840, -95.369222], zoom=19) #Create map that is centered and zoomed in m.add_basemap("SATELLITE") #Add satellite image to map m #Display map
已尝试重启内核、重新打开文件,问题仍存在。
解决方案
- 重装依赖包:大概率是jupyter-leaflet(对应PyPI包
ipyleaflet)的文件损坏或版本冲突,执行以下命令:pip uninstall -y ipyleaflet jupyter-leaflet pip install ipyleaflet jupyter-leaflet - 重建Jupyter前端扩展:
- 若使用Jupyter Lab:
jupyter lab build - 若使用经典Notebook:
jupyter nbextension enable --py ipyleaflet
- 若使用Jupyter Lab:
- 清除浏览器缓存:按
Ctrl+Shift+R强制刷新Notebook页面,或者直接清除浏览器缓存后重新打开,避免旧的JS缓存文件干扰加载 - 指定稳定版本安装:如果新版本兼容性有问题,可安装经过验证的稳定版本,比如:
pip install ipyleaflet==0.17.0
内容的提问来源于stack exchange,提问作者jschen587
相关产品推荐
相关产品推荐

