我在Pycharm上使用Jupyter Notebook的时候,发现无法正常使用,Jupyter Server无法正常拉起来。
File "C:\Users\chgagnon\AppData\Roaming\Python\Python38\site-packages\notebook\traittypes.py", line 235, in _resolve_classes
klass = self._resolve_string(klass)
File "C:\Users\chgagnon\AppData\Roaming\Python\Python38\site-packages\traitlets\traitlets.py", line 2009, in _resolve_string
return import_item(string)
File "C:\Users\chgagnon\AppData\Roaming\Python\Python38\site-packages\traitlets\utils\importstring.py", line 30, in import_item
module = __import__(package, fromlist=[obj])
ModuleNotFoundError: No module named 'jupyter_server.contents'
当我在终端中运行时,我也遇到了同样的错误。jupyter notebook
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/notebook/traittypes.py", line 235, in _resolve_classes
klass = self._resolve_string(klass)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/traitlets/traitlets.py", line 2009, in _resolve_string
return import_item(string)
^^^^^^^^^^^^^^^^^^^
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/traitlets/utils/importstring.py", line 30, in import_item
module = __import__(package, fromlist=[obj])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**ModuleNotFoundError: No module named 'jupyter_server.contents'**
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/yaseen/anaconda3/envs/ptenv/bin/jupyter-notebook", line 10, in <module>
sys.exit(main())
^^^^^^
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/jupyter_core/application.py", line 285, in launch_instance
return super().launch_instance(argv=argv, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/traitlets/config/application.py", line 1044, in launch_instance
app = cls.instance(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/traitlets/config/configurable.py", line 555, in instance
inst = cls(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/traitlets/traitlets.py", line 1295, in __new__
inst.setup_instance(*args, **kwargs)
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/traitlets/traitlets.py", line 1338, in setup_instance
super(HasTraits, self).setup_instance(*args, **kwargs)
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/traitlets/traitlets.py", line 1314, in setup_instance
init(self)
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/notebook/traittypes.py", line 226, in instance_init
self._resolve_classes()
File "/home/yaseen/anaconda3/envs/ptenv/lib/python3.11/site-packages/notebook/traittypes.py", line 238, in _resolve_classes
warn(f"{klass} is not importable. Is it installed?", ImportWarning)
TypeError: warn() missing 1 required keyword-only argument: 'stacklevel'
降级到版本也可以在我的情况下修复它:
conda install traitlets==5.9.0 -c conda-forge
这样之后,便可以顺利使用!