Opened 4 months ago

Closed 3 months ago

#69244 closed defect (fixed)

py311-notebook: ModuleNotFoundError: No module named 'jupyter_server.contents'

Reported by: jolivetr Owned by: stromnov (Andrey Stromnov)
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc: Michael-P-Allen (Mike Allen), dershow, khorton (Kevin Horton), essandess (Steve Smith), DanyPPage, agl2015, p-bro, jjstickel (Jonathan Stickel)
Port: py311-notebook

Description

Dear all,

I am facing an issue I cannot seem to be able to solve myself. I am trying to install jupyter notebook and the latest version of the port gives me the 6.4 while it conflicts with the latest version of traitlets for some warning issue (from what I have understood from my browsing various forums on the web).

Here is the message I get

dhcp140 21:27:53 ~/Downloads > jupyter notebook
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/notebook/traittypes.py", line 235, in _resolve_classes
    klass = self._resolve_string(klass)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/traitlets/traitlets.py", line 2015, in _resolve_string
    return import_item(string)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/traitlets/utils/importstring.py", line 33, 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 "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/bin/jupyter-notebook", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/jupyter_core/application.py", line 277, in launch_instance
    return super().launch_instance(argv=argv, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/traitlets/config/application.py", line 1073, in launch_instance
    app = cls.instance(**kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/traitlets/config/configurable.py", line 583, in instance
    inst = cls(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/traitlets/traitlets.py", line 1292, in __new__
    inst.setup_instance(*args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/traitlets/traitlets.py", line 1335, in setup_instance
    super(HasTraits, self).setup_instance(*args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/traitlets/traitlets.py", line 1311, in setup_instance
    init(self)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/notebook/traittypes.py", line 226, in instance_init
    self._resolve_classes()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/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'

Most answers I found point to the fact that notebook is calling for a private method of traitlets called warn while it should be calling for warnings.warn, which is public. I'd like to push forward a newer version of notebook (7.x.x?) but that involves a lot of dependencies and I don't know which ones must be pushed forward. In the meantime, I'll work out a dirty hack, if I can...

Thanks for the help and for the fix, if possible. If there is something wrong on my side, I am happy to be taught (I just uninstalled/reinstalled macports to fix this). It was working with python38 and broke since I am trying to move to python311 (yeah, I know, I am late...)

Cheers, R

Attachments (1)

jupyter-3.12_notebook.log (2.8 KB) - added by Michael-P-Allen (Mike Allen) 4 months ago.
Error messages from jupyter-3.12 notebook

Download all attachments as: .zip

Change History (22)

comment:1 Changed 4 months ago by ryandesign (Ryan Carsten Schmidt)

Keywords: jupyter notebook removed
Owner: set to stromnov
Priority: HighNormal
Status: newassigned
Summary: Problem of versions of jupyter notebook and traitletspy311-notebook: ModuleNotFoundError: No module named 'jupyter_server.contents'

comment:2 Changed 4 months ago by Michael-P-Allen (Mike Allen)

I get exactly the same errors using a Macports distribution based on py312. For me, the error started when port upgrade outdated installed the latest version of py312-traitlets @5.14.1_0, released a few days ago. The error goes away when I revert to the previous version of py312-traitlets @5.9.0_0.

Last edited 4 months ago by Michael-P-Allen (Mike Allen) (previous) (diff)

Changed 4 months ago by Michael-P-Allen (Mike Allen)

Attachment: jupyter-3.12_notebook.log added

Error messages from jupyter-3.12 notebook

comment:3 Changed 4 months ago by jolivetr

Indeed, that works. I also have to downgrade anyio to version @3.7.1_0 otherwise, a warning shows up stating that run_sync_in_worker_threads is not available.

Last edited 4 months ago by jolivetr (previous) (diff)

comment:4 Changed 4 months ago by Michael-P-Allen (Mike Allen)

Cc: Michael-P-Allen added

comment:5 Changed 4 months ago by dershow

Cc: dershow added

comment:6 Changed 4 months ago by dershow

This looks like a known jupyter bug that is now in Macport versions:

https://github.com/microsoft/azuredatastudio/issues/24436 https://stackoverflow.com/questions/77549493/modulenotfounderror-no-module-named-jupyter-server-contents

For me it is also present in py39-notebook and py310-notebook

comment:7 Changed 4 months ago by khorton (Kevin Horton)

Cc: khorton added

comment:8 Changed 3 months ago by ryandesign (Ryan Carsten Schmidt)

Cc: essandess DanyPPage added

Has duplicates #69306, #69298.

comment:9 Changed 3 months ago by ryandesign (Ryan Carsten Schmidt)

Cc: agl2015 added

Has duplicate #69358.

comment:10 Changed 3 months ago by dyne2meter

I followed the instructions for reverting, but I was only able to install py-traitlets 5.9, and not able to locate (let alone, revert) either py311-traitlets or py312-traitlets. Maybe it's buried somewhere in py-traitlets, but most of macports is a black box to me.

comment:11 Changed 3 months ago by bquast (Bastiaan Quast)

I get this

 ~ % sudo port install py-traitlets @5.9.0_0 
Error: py-traitlets version 5.9.0_0 is not available (current version is 5.14.1_0)

and

 ~ % sudo port install py312-traitlets @5.9.0_0
Error: py312-traitlets version 5.9.0_0 is not available (current version is 5.14.1_0)

any ideas?

comment:12 Changed 3 months ago by essandess (Steve Smith)

Temporary fix:

sudo port uninstall py*-traitlets
sudo pip3 install traitlets==5.9.0
Last edited 3 months ago by essandess (Steve Smith) (previous) (diff)

comment:13 Changed 3 months ago by dyne2meter

Using pip works, but sort of... better than nothing ...

Collecting traitlets==5.9.0
  Downloading traitlets-5.9.0-py3-none-any.whl.metadata (10 kB)
Downloading traitlets-5.9.0-py3-none-any.whl (117 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 117.4/117.4 kB 4.3 MB/s eta 0:00:00
Installing collected packages: traitlets
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
jupyter 1.0.0 requires qtconsole, which is not installed.
nbconvert 7.2.9 requires mistune<3,>=2.0.3, but you have mistune 3.0.2 which is incompatible.
Successfully installed traitlets-5.9.0

Notebook starts, but emits numerous errors (some appear related to the need to revert anyio, mentioned in a previous post):

[W 07:04:04.861 NotebookApp] Error loading server extension jupyterlab
    Traceback (most recent call last):
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/notebook/notebookapp.py", line 2025, in init_server_extensions
        mod = importlib.import_module(modulename)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 995, in exec_module
      File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyterlab/__init__.py", line 7, in <module>
        from .labapp import LabApp
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyterlab/labapp.py", line 15, in <module>
        from jupyterlab_server import slugify, WORKSPACE_EXTENSION
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyterlab_server/__init__.py", line 4, in <module>
        from .app import LabServerApp
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyterlab_server/app.py", line 7, in <module>
        from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyter_server/extension/application.py", line 21, in <module>
        from jupyter_server.serverapp import ServerApp
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyter_server/serverapp.py", line 75, in <module>
        from jupyter_server.services.contents.filemanager import AsyncFileContentsManager, FileContentsManager
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyter_server/services/contents/filemanager.py", line 15, in <module>
        from anyio import run_sync_in_worker_thread
    ImportError: cannot import name 'run_sync_in_worker_thread' from 'anyio' (/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/anyio/__init__.py)

comment:14 Changed 3 months ago by p-bro

Cc: p-bro added

comment:15 Changed 3 months ago by jjstickel (Jonathan Stickel)

Cc: jjstickel added

comment:16 Changed 3 months ago by mseri (Marcello Seri)

I don't understand why the priority is normal. This is basically breaking jupyter for everybody on any recent enough version of python

comment:17 Changed 3 months ago by dershow

And, if you work around it by using an old version of traitlets you end up hitting other bugs:

https://trac.macports.org/ticket/69419

I've created a virtual environment and then used pip to install notebook as a temporary work around. It seems that jupyter from macports is currently unusable.

comment:18 Changed 3 months ago by jjstickel (Jonathan Stickel)

comment:19 Changed 3 months ago by jjstickel (Jonathan Stickel)

Oops, I missed a colon in the "Closes" line in the PR. The PR was merged, and so this ticket may be closed.

comment:20 Changed 3 months ago by Michael-P-Allen (Mike Allen)

I can confirm that (using py312) sudo port selfupdate, sudo port upgrade outdated today (which installs py312-notebook @6.4.11_1 amongst others) followed by sudo port activate py312-traitlets @5.14.1_0 (to bring me back up to date with the current version) seems to fix this for me.

Last edited 3 months ago by Michael-P-Allen (Mike Allen) (previous) (diff)

comment:21 Changed 3 months ago by reneeotten (Renee Otten)

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.