ipykernel (Jupyter notebook/labs) 无法从 traitlets.utils 导入名称“filefind”

ipykernel (Jupyter notebook/labs) cannot import name ''filefind" from traitlets.utils

我在 EC2 实例上安装了 Jupyter notebook 和 labs,但出于某种原因我收到以下错误:

ImportError: cannot import name 'filefind' from 'traitlets.utils' (/usr/lib/python3/dist-packages/traitlets/utils/init.py)

Jupyter 在浏览器中可以正常打开,但我似乎无法在 python 笔记本中工作。

肮脏的初始修复(不推荐):

好的,修好了! 问题似乎是“traitlets/utils/init.py”是空的。 所以我从 GitHub 复制粘贴了代码并且成功了。

https://github.com/ipython/traitlets/blob/main/traitlets/utils/__init__.py

我在安装两个不同的 ec2 实例安装 cuda 和 cudnn 时遇到了这个问题两次。所以这可能与这个问题的起源有关。

正确修复:

解决此问题的正确方法是 upgrading/downgrading 库。查看此 post 的其他答案以获取指导。

我不鼓励op的解决方案。下载和覆盖 python 库并不是保持系统稳定和干净的方法!

我发现在安装 Jupyter notebook 时它发现了四个重大错误,这些错误是由于 python3 个软件包在该安装本身中没有正确安装。

ERROR: ipykernel 6.6.0 has requirement traitlets<6.0,>=5.1.0, but you'll have traitlets 4.3.3 which is incompatible. ERROR: jupyterlab-pygments 0.1.2 has requirement pygments<3,>=2.4.1, but you'll have pygments 2.3.1 which is incompatible. ERROR: nbconvert 6.3.0 has requirement pygments>=2.4.1, but you'll have pygments 2.3.1 which is incompatible. ERROR: nbconvert 6.3.0 has requirement traitlets>=5.0, but you'll have traitlets 4.3.3 which is incompatible.

解决方案是将软件包修补到最新版本:

pip3 install traitlets==5.1.1

pip3 install pygments==2.4.1

这适用于过时的软件包阻止您安装的所有类似情况

我遇到了同样的问题。按照@luarzou 的建议,单独降级 traitlets 和 pygments 的版本并没有解决我的问题。 我还降级了 ipykernel,它现在可以工作了:

pip install ipykernel==6.0

我打开了一个问题: https://github.com/ipython/ipykernel/issues/857

编辑:实际上,当您的 venv 具有不同于 env 运行 jupyter 的 ipykernel 或其依赖项版本时,可能会发生此错误。在这种情况下,我建议删除并重新创建您的 venv,并确认您没有在那里安装会破坏 communication/compatibility.

的软件包