python - 安装时 ipyleaflet map 未在 jupyter 笔记本中渲染

标签 python python-3.x jupyter-notebook ipyleaflet

在笔记本中运行以下命令:

!pip install ipyleaflet
!jupyter nbextension enable --py --sys-prefix ipyleaflet

成功注册ipyleaflet扩展:

Enabling notebook extension jupyter-leaflet/extension...
      - Validating: ok

但是在同一笔记本中渲染 map 不起作用:

from ipyleaflet import Map, basemaps
Map(
    center=(0, 0),
    zoom=1,
    scroll_wheel_zoom=True,
    basemap=basemaps.OpenStreetMap.Mapnik,
)

错误:

[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'LeafletMapModel' from module 'jupyter-leaflet'
Error: Script error for "jupyter-leaflet"
http://requirejs.org/docs/errors.html#scripterror
    at makeError (http://localhost:8888/static/components/requirejs/require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:168:17)
    at HTMLScriptElement.onScriptError (http://localhost:8888/static/components/requirejs/require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:1735:36)

浏览器说

Refused to execute script from 'http://localhost:8888/static/jupyter-leaflet.js?v=20221102111053' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

现有的解决方案是将 Jupyter Notebook 升级到 5.7.7,但我使用的是 6.5.2 版本。

如果我使用笔记本重新加载页面,ipyleaflet map 将正确显示。

我怎样才能让它在第一遍就起作用?

最佳答案

我在运行 Jupyter Notebook 时收到了相同的错误,但重新启动内核,然后关闭并重新打开该文件对我有用。

关于python - 安装时 ipyleaflet map 未在 jupyter 笔记本中渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74287757/

相关文章:

csv - 在python中格式化CSV文件中的数据(计算平均值)

python - 使用解析器模块检查 Python 3 源代码中的严重错误

python-3.x - 使用 NaiveBayesClassifier 对文本进行分类

path - 如何更改 Jupyter 启动文件夹

python - 值错误: Input 0 of layer dense_1 is incompatible with the layer

python - 从部分圆形中寻找圆形

python - 如何搜索文件中的值并替换

python - 使用 OpenCV 直方图均衡化时遇到问题

python - 使用 BeautifulSoup 提取图像链接

python - 如何在浏览器中增加 Jupyter/ipython 笔记本的单元格宽度?