Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't open the jupyter notebook after the jupytext installation #1020

Closed
cacoto opened this issue Dec 5, 2022 · 17 comments · May be fixed by #1021
Closed

Can't open the jupyter notebook after the jupytext installation #1020

cacoto opened this issue Dec 5, 2022 · 17 comments · May be fixed by #1021

Comments

@cacoto
Copy link

cacoto commented Dec 5, 2022

I followed the documentation and installed the jupytext into my environment.
When I tried to open the jupyter notebook, it gave me an error as following:
[C 17:38:32.393 NotebookApp] Bad config encountered during initialization: The 'contents_manager_class' trait of a NotebookApp instance expected a subclass of notebook.services.contents.manager.ContentsManager or jupyter_server.contents.services.managers.ContentsManage, not the JupytextContentsManager JupytextContentsManager.

@mwouts
Copy link
Owner

mwouts commented Dec 6, 2022

Hello @cacoto , could you tell us more about how exactly you created your Python environment, and how you installed Jupytext? In particular, do you use a custom Jupyter configuration file? Also, which version of Jupyter are you using (jupyter --version)

@kdm9
Copy link
Contributor

kdm9 commented Dec 7, 2022

hitting the same issue @mwouts. This was simply pip install -U juptyer notebook jupyterlab jupytext'd to my home dir. Jupytext version 1.14.2.

Log below has some hashes/tokens/cookies/secrets cut out and replaced with -------->8-----------

[I 2022-12-07 19:17:49.410 LabApp] Generating new user for token-authenticated request: -------->8-----------
~/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py:194: RuntimeWarning: coroutine 'AsyncFileContentsManager.file_exists' was never awaited
  if (
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
~/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py:194: RuntimeWarning: coroutine 'AsyncFileContentsManager.dir_exists' was never awaited
  if (
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[I 2022-12-07 19:17:51.567 LabApp] Build is up to date
[I 2022-12-07 19:17:53.253 ServerApp] Creating new notebook in 
~/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py:400: RuntimeWarning: coroutine 'AsyncFileContentsManager.dir_exists' was never awaited
  if not self.dir_exists(path):
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
~/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py:504: RuntimeWarning: coroutine 'AsyncFileContentsManager.file_exists' was never awaited
  if self.file_exists(path):
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[E 2022-12-07 19:17:53.253 ServerApp] Uncaught exception POST /api/contents?-------->8----------- (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/api/contents?-------->8-----------', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/tornado/web.py", line 1713, in _execute
        result = await result
      File "~/.local/lib/python3.10/site-packages/jupyter_server/services/contents/handlers.py", line 227, in post
        await self._new_untitled(path, type=type, ext=ext)
      File "~/.local/lib/python3.10/site-packages/jupyter_server/services/contents/handlers.py", line 175, in _new_untitled
        self.contents_manager.new_untitled(path=path, type=type, ext=ext)
      File "~/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 404, in new_untitled
        config = self.get_config(path)
      File "~/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 572, in get_config
        self.cached_config.config = self.load_config_file(
      File "~/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 541, in load_config_file
        config_content = model["content"]
    TypeError: 'coroutine' object is not subscriptable
[W 2022-12-07 19:17:53.254 ServerApp] wrote error: 'Unhandled error'
[E 2022-12-07 19:17:53.254 ServerApp] {
      "Host": "localhost:8888",
      "Accept": "*/*",
      "Referer": "http://localhost:8888/lab",
      "User-Agent": "Mozilla/5.0 -------->8-----------"
    }
$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.5.0
ipykernel        : 6.17.0
ipywidgets       : 6.0.0
jupyter_client   : 7.4.8
jupyter_core     : 5.1.0
jupyter_server   : 2.0.0
jupyterlab       : 3.5.1
nbclient         : 0.7.0
nbconvert        : 6.5.3
nbformat         : 5.5.0
notebook         : 6.5.2
qtconsole        : 5.4.0
traitlets        : 5.5.0

@mwouts
Copy link
Owner

mwouts commented Dec 7, 2022

Thank you @kdm9 for joining the conversation! Actually I am afraid your error is different of @cacoto's one, at least the exception seems different... Your error seems to be related to the parsing of a Jupytext config file (at least if I read it correctly!).

@kdm9
Copy link
Contributor

kdm9 commented Dec 8, 2022

I agree it's a different specific error/traceback, but I thought they might be related given OP's Bad config encountered during initialization: and the messages about JupytextContentsManager, which seems to be defined in the file my traceback is in (jupytext/contentsmanager.py).

To an uninformed eye it seems the jupyter api for parsing configs has been async-ified or at least changed significantly, which causes effectively the same error at various locations in the code depending on how/by what jupytext gets invoked.

This is currently blocking me from my usual daily analysis workflow, so I would be keen to see it fixed ASAP, and of course I'm willing to help expedite a fix. Do you have an approximate idea of the cause? If not, i'll dig in and see if I can find the bug.

@kdm9
Copy link
Contributor

kdm9 commented Dec 8, 2022

I'm pretty sure i've narrowed this down to jupyter-server now using async classes: jupyter-server/jupyter_server#1044

Will attempt to disable this and see if it fixes things

@kdm9
Copy link
Contributor

kdm9 commented Dec 8, 2022

Can confirm, downgrading to pip install jupyter-server==1.23.3 fixes this for me. Seems like we'll need to implement everything here in async land, as the jupyter-server folks have deprecated the synchronous classes (see jupyter-server/jupyter_server#1044)

@kdm9
Copy link
Contributor

kdm9 commented Dec 8, 2022

@cacoto if downgrading jupyter-server fixes it for you, then i'd guess we have the same root cause. If not, apologies for hijacking your issue! :)

@danielcs88
Copy link

Having the same exact issue for a couple of days. Installed python via Miniforge.

[I 2022-12-08 21:17:23.858 LabApp] Generating new user for token-authenticated request: 617683bf8f6d4062acda97936dde8578
/Users/daniel/miniforge3/lib/python3.10/site-packages/jupytext/contentsmanager.py:194: RuntimeWarning: coroutine 'AsyncFileContentsManager.file_exists' was never awaited
  if (
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
/Users/daniel/miniforge3/lib/python3.10/site-packages/jupytext/contentsmanager.py:194: RuntimeWarning: coroutine 'AsyncFileContentsManager.dir_exists' was never awaited
jupyter --version
Selected Jupyter core packages...
IPython          : 8.7.0
ipykernel        : 6.19.2
ipywidgets       : not installed
jupyter_client   : 7.4.8
jupyter_core     : 5.1.0
jupyter_server   : 2.0.1
jupyterlab       : 3.5.1
nbclient         : 0.7.2
nbconvert        : 7.2.6
nbformat         : 5.7.0
notebook         : 6.5.2
qtconsole        : not installed
traitlets        : 5.7.0   

@amitbha
Copy link

amitbha commented Dec 9, 2022

The same issue, any workaround?

# jupyter --version
Selected Jupyter core packages...
IPython          : 8.7.0
ipykernel        : 6.17.1
ipywidgets       : 8.0.2
jupyter_client   : 7.4.8
jupyter_core     : 5.1.0
jupyter_server   : 2.0.1
jupyterlab       : 3.5.1
jupytext          : 1.14.2
nbclient         : 0.7.2
nbconvert        : 7.2.6
nbformat         : 5.7.0
notebook         : 6.5.2
qtconsole        : 5.3.1
traitlets        : 5.6.0

The output:

    Traceback (most recent call last):
      File "/home/amtf/.local/lib/python3.10/site-packages/tornado/web.py", line 1713, in _execute
        result = await result
      File "/home/amtf/.local/lib/python3.10/site-packages/jupyter_server/services/contents/handlers.py", line 227, in post
        await self._new_untitled(path, type=type, ext=ext)
      File "/home/amtf/.local/lib/python3.10/site-packages/jupyter_server/services/contents/handlers.py", line 175, in _new_untitled
        self.contents_manager.new_untitled(path=path, type=type, ext=ext)
      File "/home/amtf/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 404, in new_untitled
        config = self.get_config(path)
      File "/home/amtf/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 572, in get_config
        self.cached_config.config = self.load_config_file(
      File "/home/amtf/.local/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 541, in load_config_file
        config_content = model["content"]
    TypeError: 'coroutine' object is not subscriptable

@danielcs88
Copy link

@amitbha I had to manually do all the things suggested here

https://jupytext.readthedocs.io/en/latest/install.html

If you don’t have the notebook icon on text documents after a fresh restart of your Jupyter server, you can either enable our server extension explicitly (with jupyter serverextension enable jupytext), or install the contents manager manually. Append

c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"

and I ran the following

jupyter labextension install jupyterlab-jupytext

Did it fix it? Yes.

GIF

Am I confident in my Jupyter config that is super convoluted, not quite.

@amitbha
Copy link

amitbha commented Dec 9, 2022

@amitbha I had to manually do all the things suggested here

https://jupytext.readthedocs.io/en/latest/install.html

If you don’t have the notebook icon on text documents after a fresh restart of your Jupyter server, you can either enable our server extension explicitly (with jupyter serverextension enable jupytext), or install the contents manager manually. Append

c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"

and I ran the following

jupyter labextension install jupyterlab-jupytext

Did it fix it? Yes.

Thanks.
I tried, but nothing changed.

@kdm9
Copy link
Contributor

kdm9 commented Dec 9, 2022

@amitbha @danielcs88 try downgrading jupyter_server to 1.23.3. @danielcs88's solution undoes the change in jupyter-server/jupyter_server#1044 which makes the Async content manager classes the default, so this seems to be further evidence that the new default of using async content managers with juptyer_server 2.0.0 is responsible.

@st-bender
Copy link

st-bender commented Dec 10, 2022

Hi there,

Sorry for jumping in. It looks like the three lines in

app.contents_manager_class = build_jupytext_contents_manager_class(
app.contents_manager_class
)
should really read something like:

app.contents_manager_class = TextFileContentsManager

Cheers.

@mwouts
Copy link
Owner

mwouts commented Dec 10, 2022

Thank you @kdm9 for diagnosing this! This is very helpful.

I am able to reproduce the issue locally so I'll be working on making Jupytext compatible with async contents manager asap.

For now the workarounds are to

  • either downgrade jupyter_server to 1.23.3
  • or, use a Jupytext contents manager that is not derived from an async contents manager. One way to do so is to set
c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"

in your Jupyter Notebook config file.

Now the reason why the error is not spotted by the CI is that the contents manager used in tests is jupytext.TextFileContentsManager, while for most users (those without an explicit contents manager class in their config) we build a TextFileContentsManager based on the default CM class:

app.contents_manager_class = build_jupytext_contents_manager_class(
app.contents_manager_class
)

Finally let me explain why jupytext.TextFileContentsManager does not show the issue (either in tests or in the custom config) - it's because most often it is derived from LargeFileManager, cf.

try:
# The LargeFileManager is taken by default from jupyter_server if available
from jupyter_server.services.contents.largefilemanager import LargeFileManager
TextFileContentsManager = build_jupytext_contents_manager_class(LargeFileManager)
except ImportError:
# If we can't find jupyter_server then we take it from notebook
try:
from notebook.services.contents.largefilemanager import LargeFileManager
TextFileContentsManager = build_jupytext_contents_manager_class(
LargeFileManager
)
except ImportError:
# Older versions of notebook do not have the LargeFileManager #217
from notebook.services.contents.filemanager import FileContentsManager
TextFileContentsManager = build_jupytext_contents_manager_class(
FileContentsManager
)

@mwouts
Copy link
Owner

mwouts commented Dec 10, 2022

Sorry for jumping in. It looks like the three lines in

app.contents_manager_class = build_jupytext_contents_manager_class(

should really read something like:

app.contents_manager_class = TextFileContentsManager

Well, I prefer to provide a contents manager that looks as close as possible to the original one, and that's the reason for that line (plus, there have been already three different default CM since we started this project, not even counting the new async one!). But sure we need to make sure this works for every base CM, I will add more tests to ensure that.

@mwouts
Copy link
Owner

mwouts commented Dec 11, 2022

As a quick fix I have released jupytext==1.14.3 which will use LargeFileManager as the base contents manager instead of the default CM when that one has async in its name. @kdm9, @cacoto or @danielcs88 can you confirm that version fixes the issue here?

Then the plan is to make the Jupytext CM async - that should come in jupytext==1.15.0 (please follow #1021 for updates)

@kdm9
Copy link
Contributor

kdm9 commented Dec 11, 2022

@mwouts brilliant, jupytext==1.14.4 fixed it for me :) Thanks for a speedy resolution!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants