在 Pipenv 中运行 Jupyter Lab 时,Ipympl 输出“显示小部件时出错:未找到模型”

CSS*_*782 7 python python-3.x jupyter-notebook pipenv

操作系统:Ubuntu 18.04.6 LTS

安装:

在尝试使用时遇到此问题后,我从新的使用中pipenv install jupyterlab安装了所有内容。pip installpipenv shellPython 3.8.0

pipenv shell
pip install --upgrade pip
pip install numpy matplotlib jupyterlab ipympl
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到 Jupyter Lab 安装文档。

运行pip list输出:

Package              Version
-------------------- ---------
anyio                3.5.0
argon2-cffi          21.3.0
argon2-cffi-bindings 21.2.0
asttokens            2.0.5
attrs                21.4.0
Babel                2.9.1
backcall             0.2.0
black                21.12b0
bleach               4.1.0
certifi              2021.10.8
cffi                 1.15.0
charset-normalizer   2.0.10
click                8.0.3
cycler               0.11.0
debugpy              1.5.1
decorator            5.1.1
defusedxml           0.7.1
entrypoints          0.3
executing            0.8.2
fonttools            4.28.5
idna                 3.3
importlib-resources  5.4.0
ipykernel            6.7.0
ipympl               0.8.7
ipython              8.0.1
ipython-genutils     0.2.0
ipywidgets           7.6.5
jedi                 0.18.1
Jinja2               3.0.3
json5                0.9.6
jsonschema           4.4.0
jupyter-client       7.1.1
jupyter-core         4.9.1
jupyter-server       1.13.3
jupyterlab           3.2.8
jupyterlab-pygments  0.1.2
jupyterlab-server    2.10.3
jupyterlab-widgets   1.0.2
kiwisolver           1.3.2
MarkupSafe           2.0.1
matplotlib           3.5.1
matplotlib-inline    0.1.3
mistune              0.8.4
mypy-extensions      0.4.3
nbclassic            0.3.5
nbclient             0.5.10
nbconvert            6.4.0
nbformat             5.1.3
nest-asyncio         1.5.4
notebook             6.4.7
numpy                1.22.1
packaging            21.3
pandocfilters        1.5.0
parso                0.8.3
pathspec             0.9.0
pexpect              4.8.0
pickleshare          0.7.5
Pillow               9.0.0
pip                  21.3.1
pkg_resources        0.0.0
platformdirs         2.4.1
prometheus-client    0.12.0
prompt-toolkit       3.0.24
ptyprocess           0.7.0
pure-eval            0.2.1
pycparser            2.21
Pygments             2.11.2
pyparsing            3.0.7
pyrsistent           0.18.1
python-dateutil      2.8.2
pytz                 2021.3
pyzmq                22.3.0
requests             2.27.1
Send2Trash           1.8.0
setuptools           60.5.0
six                  1.16.0
sniffio              1.2.0
stack-data           0.1.4
terminado            0.12.1
testpath             0.5.0
tomli                1.2.3
tornado              6.1
traitlets            5.1.1
typing_extensions    4.0.1
urllib3              1.26.8
wcwidth              0.2.5
webencodings         0.5.1
websocket-client     1.2.3
wheel                0.37.1
widgetsnbextension   3.5.2
zipp                 3.7.0
Run Code Online (Sandbox Code Playgroud)

值得注意的是jupyterlab==3.2.8matplotlib==3.5.1并且ipympl==0.8.7满足版本查找表

jupyter lab --ip 0.0.0.0 --no-browser现在从 pipelinev shell 内部运行(--ip 0.0.0.0 --no-browser因为我正在另一台机器上访问笔记本)。

使用默认Python 3 (ipykernel)内核打开一个新笔记本,创建两个单元

from matplotlib import pyplot as plt
import ipympl  # Confirming it is being found by the kernel
Run Code Online (Sandbox Code Playgroud)
%matplotlib widget

# Example found from /sf/ask/3510469371/

plt.figure()
x = [1,2,3]
y = [4,5,6]
plt.plot(x,y)
plt.show()
Run Code Online (Sandbox Code Playgroud)

运行这两个单元格会给出常见的错误消息:

Error displaying widget: model not found
Run Code Online (Sandbox Code Playgroud)

我已经尝试过的:

这个问题

我降级的地方:

ipywidgets==7.0.0
ipympl==0.2.1
matplotlib==3.2.0
Run Code Online (Sandbox Code Playgroud)

并安装

jupyter labextension install jupyter-matplotlib@0.3.0
Run Code Online (Sandbox Code Playgroud)

没有改变,同样的错误。


编辑:使用 Jupyter Notebook 而不是 Jupyter Lab,这意味着pip install jupyter而不是jupyterlab解决问题。

这就是我在这里代替答案所做的,但仍然想知道是否有人对 Jupyter Lab 有直接的修复。