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

Jupytext does not pair notebooks in Jupyterlab #298

Closed
augusto-herrmann opened this issue Jul 19, 2019 · 11 comments
Closed

Jupytext does not pair notebooks in Jupyterlab #298

augusto-herrmann opened this issue Jul 19, 2019 · 11 comments

Comments

@augusto-herrmann
Copy link

Hi. I have installed Jupytext following the instructions in the README, using pip. I used jupyter lab build after installation. The versions I'm using are:

$ pip3 freeze | grep jupyterlab
jupyterlab==1.0.2
jupyterlab-server==1.0.0

$ pip3 freeze | grep jupytext
jupytext==1.1.7

The commands do appear in JupyterLab UI, just as described in the documentation:

JupyterLab extension

However, if I use the UI to try to pair a notebook, nothing happens. If I save the notebook, no new file in .md, .py or whatever format is ever created.

If I do the following in the command line:

$ jupytext --set-formats ipynb,md --sync my.ipynb 
[jupytext] Reading my.ipynb
[jupytext] Updating notebook metadata with '{"jupytext": {"formats": "ipynb,md"}}'
[jupytext] Loading notebook from 'my.ipynb'
[jupytext] Updating 'my.ipynb'
[jupytext] Updating 'my.md'

then it does create the .md file, as expected. But if I open the file in JupyterLab, change something, and save, the markdown file remains unchanged. I have to manually run jupytext in the command line every time.

Is this a bug? Is there a workaround?

@marco-matta
Copy link

marco-matta commented Jul 19, 2019

Try to pip3 install jupytext==1.2, this is the newer version that should work with latest jupyterlab

@mwouts
Copy link
Owner

mwouts commented Jul 19, 2019

Hello @augusto-herrmann , thanks for reporting this. Can you quote the first lines of logs when you execute jupyter lab? Do you see any mention of Jupyter's contents manager being replaced with a JupytextContentsManager? And, what kind of icon do you get for Markdown files in JupyterLab?

@augusto-herrmann
Copy link
Author

No, @mwouts. There is no mention of content managers or Jupytext at all in the Jupyer Lab logs:

$ jupyter lab
[W 16:35:10.939 LabApp] JupyterLab server extension not enabled, manually loading...
[I 16:35:10.942 LabApp] JupyterLab extension loaded from /home/mypath/.local/lib/python3.6/site-packages/jupyterlab
[I 16:35:10.942 LabApp] JupyterLab application directory is /home/mypath/.local/share/jupyter/lab
[I 16:35:10.943 LabApp] Serving notebooks from local directory: /home/mypath/dev/plataforma-indicadores
[I 16:35:10.943 LabApp] The Jupyter Notebook is running at:
[I 16:35:10.943 LabApp] http://localhost:8888/?token=e94565a565b656c...c5ab528d52b8
[I 16:35:10.943 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 16:35:10.946 LabApp] 
    
    To access the notebook, open this file in a browser:
        file:///home/mypath/.local/share/jupyter/runtime/nbserver-32224-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=e94565a565b656c...c5ab528d52b8
[I 16:35:14.210 LabApp] Build is up to date

I also tried installing jupytext==1.2, as suggested by @marco-matta96. Still no mention of content managers or Jupytext in the logs:

$ jupyter lab
[W 16:50:38.083 LabApp] JupyterLab server extension not enabled, manually loading...
[I 16:50:38.086 LabApp] JupyterLab extension loaded from /home/mypath/.local/lib/python3.6/site-packages/jupyterlab
[I 16:50:38.086 LabApp] JupyterLab application directory is /home/mypath/.local/share/jupyter/lab
[I 16:50:38.087 LabApp] Serving notebooks from local directory: /home/mypath/dev/plataforma-indicadores
[I 16:50:38.088 LabApp] The Jupyter Notebook is running at:
[I 16:50:38.088 LabApp] http://localhost:8888/?token=e94565a565b656c...c5ab528d52b8
[I 16:50:38.088 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 16:50:38.090 LabApp] 
    
    To access the notebook, open this file in a browser:
        file:///home/mypath/.local/share/jupyter/runtime/nbserver-32673-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=e94565a565b656c...c5ab528d52b8
[I 16:50:40.675 LabApp] 301 GET /lab/workspaces/auto-j/?clone (127.0.0.1) 0.80ms
[I 16:50:43.509 LabApp] Build is up to date

However, now Jupytext commands in the Jupyter Lab UI still appear, but became disabled (greyed out). I did remember to run jupyter lab build after upgrading to 1.2.

jupytext-greyed-out

Previously, in version 1.1.7, they did appear, but had no apparent effect besides putting a check mark next to the selected pairing option.

Strangely, with the command jupyter labextension, jupytext appears with the wrong version number:

$ jupyter labextension list
JupyterLab v1.0.2
Known labextensions:
   app dir: /home/herrmann/.local/share/jupyter/lab
        @jupyterlab/plotly-extension v1.0.0  enabled  OK
        jupyterlab-jupytext v1.0.1  enabled  OK

@mwouts
Copy link
Owner

mwouts commented Jul 20, 2019

The expected log when Jupyter starts is something like:

(python3) C:\Users\Marc>jupyter lab
[I 06:34:18.243 LabApp] JupyterLab extension loaded from C:\Users\Marc\Miniconda3\envs\python3\lib\site-packages\jupyterlab
[I 06:34:18.243 LabApp] JupyterLab application directory is C:\Users\Marc\Miniconda3\envs\python3\share\jupyter\lab
[I 06:34:20.300 LabApp] [Jupytext Server Extension] Deriving a JupytextContentsManager from LargeFileManager
[I 06:34:20.302 LabApp] Serving notebooks from local directory: C:\Users\Marc
...

The difference with yours is that the Jupytext server extension is not active. Could you execute

jupyter serverextension enable jupytext

and restart jupyter lab?

If for some reason you cannot activate the server extension, you still have the option to explicitly set the Contents Manager to Jupytext's one in your jupyter_notebook_config.py file with

c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"

Regarding your question about version numbers: 1.0.1 is the version of the jupyterlab-jupytext extension, which is numbered separately from jupytext. And in the latest version, some commands are greyed when the selected file is not an ipynb notebook - not all pairing commands apply in that case. But that is not related to your issue.

@augusto-herrmann
Copy link
Author

That did it! Now it works. Thank you, @mwouts.

Maybe that step should be added to the Jupyter Lab installation instructions in the documentation?

jupyter serverextension enable jupytext

@hoangthienan95
Copy link

hoangthienan95 commented Aug 22, 2019

@mwouts I was using jupytext fine before but now the commands have disappeared. I think it's because I installed some extensions that might have interfere with jupytext or jupyterlab. Just trying to confirm this is not a problem with Jupytext itself.

My start of Jupyterlab is below:

[I 18:19:50.772 LabApp] JupyterLab extension loaded from /lab/corradin_data/FOR_AN/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 18:19:50.772 LabApp] JupyterLab application directory is /lab/corradin_data/FOR_AN/anaconda3/share/jupyter/lab
[I 18:19:51.789 LabApp] [Jupytext Server Extension] Changing NotebookApp.contents_manager_class from LargeFileManager to jupytext.TextFileContentsManager
[W 18:19:51.885 LabApp] JupyterLab server extension not enabled, manually loading...
[I 18:19:52.249 LabApp] JupyterLab extension loaded from /lab/corradin_data/FOR_AN/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 18:19:52.250 LabApp] JupyterLab application directory is /lab/corradin_data/FOR_AN/anaconda3/share/jupyter/lab
[I 18:19:52.250 LabApp] Serving notebooks from local directory: /lab/corradin_data/FOR_AN

Editing to add that Jupytext in Jupyter Notebook works fine, and the icons for .py files still remain notebook icons in Jupyter Lab. Just the jupytext commands have disappeared/ not visible from Commands tab search. Very weird...

> jupyter serverextension list

config dir: /home/anhoang/.jupyter
    jupytext  enabled 
    - Validating...
      jupytext 1.1.1 OK
config dir: /lab/corradin_data/FOR_AN/anaconda3/etc/jupyter
    jupyterlab  enabled 
    - Validating...
      jupyterlab 0.35.3 OK
    jupytext  enabled 
    - Validating...
      jupytext 1.1.1 OK
    scriptedforms  enabled 
    - Validating...
      scriptedforms 0.10.1 OK
    beakerx  enabled 
    - Validating...
      beakerx 1.4.1 OK

@mwouts
Copy link
Owner

mwouts commented Aug 22, 2019

Hello @hoangthienan95 , your issue may be related to the publication of JupyterLab 1.0, which made the first version of our extension incompatible with JupyterLab 0.35 (see #276 and the resolution at #278). You can either

  • continue using JupyterLab 0.35 and install the last version of our extension compatible with that version: jupyter labextension install [email protected]
  • or, update both JupyterLab and our extension for Jupyter Lab (jupyter labextension install jupyterlab-jupytext)

@hoangthienan95
Copy link

Hi @mwouts , thanks so much for the rapid reply as always! And yes, I tried jupyter labextension install [email protected] on a hunch and it fixed that for me. Thanks!

@mwouts
Copy link
Owner

mwouts commented Sep 1, 2019

I'm going to close this issue, which was originally about the Jupytext server extension for Jupyter not being active. Now, thanks to #304, we do have a mention about that extension in the documentation.

@mwouts mwouts closed this as completed Sep 1, 2019
@yasirroni
Copy link

I've followed the docs and this issue but still unable to resolve my issue in jupyterlab

The log when starting Jupyter Lab shown like this

[I 2021-03-08 11:33:13.990 LabApp] JupyterLab extension loaded from /home/USERNAME/.local/lib/python3.8/site-packages/jupyterlab
[I 2021-03-08 11:33:13.990 LabApp] JupyterLab application directory is /home/USERNAME/.local/share/jupyter/lab
[I 2021-03-08 11:33:13.992 ServerApp] jupyterlab | extension was successfully loaded.
[I 2021-03-08 11:33:13.992 ServerApp] Serving notebooks from local directory: /home/USERNAME/Data/jupyterlab

Version:

jupyter --version

jupyter core     : 4.7.1
jupyter-notebook : 6.2.0
qtconsole        : not installed
ipython          : 7.21.0
ipykernel        : 5.5.0
jupyter client   : 6.1.11
jupyter lab      : 3.0.9
nbconvert        : 6.0.7
ipywidgets       : not installed
nbformat         : 5.1.2
traitlets        : 5.0.5

What I have done:

  1. Modify jupyter notebook --generate-config >> c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"
  2. jupyter serverextension enable jupytext
  3. jupyter nbextension install --user --py jupytext + jupyter nbextension enable jupytext --user --py

@mwouts
Copy link
Owner

mwouts commented Mar 15, 2021

Hi @yasirroni, thanks for talking the time to comment.

As this issue is rather old, I am not sure that the problem you experience is the same as the one reported here. Would you mind opening a new issue?

I'll need to know exactly how you created your Python environment, and also what is wrong. If possible, please do not modify your Jupyter configuration, nor activate or enable any extension, as they are expected to be activated automatically (happy to investigate if that is not the case).

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

No branches or pull requests

5 participants