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 not pairing file.ipynb with file.py #868

Closed
connerCpowell opened this issue Oct 12, 2021 · 3 comments
Closed

Jupytext not pairing file.ipynb with file.py #868

connerCpowell opened this issue Oct 12, 2021 · 3 comments

Comments

@connerCpowell
Copy link

I am currently struggling to get jupytext to actually pair file.ipynb with file.py.
For reference I am running Ubuntu 20.04.3 LTS

I have jupytext installed:
(env38) pukowski@pukowski:~/sandbox/proj1$ jupyter serverextension list
config dir: /home/pukowski/.jupyter
jupytext enabled
- Validating...
jupytext 1.13.0 OK

and I have also run:
jupyter serverextension enable jupytext

I can run jupytext from the command line as so:
jupytext --to py notebook.ipynb
[jupytext] Reading Untitled.ipynb in format ipynb
[jupytext] Writing Untitled.py

And it appears that my extension are fully loaded/linked based on the first few lines of my jupyter log
(env38) pukowski@pukowski:~/sandbox/proj1$ jupyter lab
[I 2021-10-12 15:51:16.693 ServerApp] jupyterlab | extension was successfully linked.
[I 2021-10-12 15:51:16.716 LabApp] JupyterLab extension loaded from /home/pukowski/.local/lib/python3.8/site-packages/jupyterlab
[I 2021-10-12 15:51:16.716 LabApp] JupyterLab application directory is /home/pukowski/.local/share/jupyter/lab
[I 2021-10-12 15:51:16.719 ServerApp] jupyterlab | extension was successfully loaded.
[I 2021-10-12 15:51:16.720 ServerApp] Serving notebooks from local directory: /home/pukowski/sandbox/proj1

HOWEVER, when I interact with the jupyter lab in my browser and run (ctrl+shift+C) to inspect the file... even though is 'checked off' that it is a 'Pair notebook with a percent script', the files are not linked... No new file is created when I save the file.ipynb, I cannot open the file.ipynb as a .py or vice versa. Here is an image of my jupyter lab set up in the browser :
Screenshot from 2021-10-12 16-19-41

The virtual environment I am using is only to compartmentalize the requirements, etc but here it is for reference
(env38) pukowski@pukowski:~/sandbox/proj1$ echo $PATH
/home/pukowski/sandbox/proj1/env38/bin:/home/pukowski/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/pukowski/.local/bin

pukowski@pukowski:~/sandbox/proj1$ echo $PATH
/home/pukowski/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/pukowski/.local/bin

I apologies if this is vague or just another one-off improper installation sort of deals but I am really trying to understand what I may have done wrong, how to fix it as well as improve my understanding of jupyter and python as a whole.

Any information or help would be greatly appreciated!
Thank you for reading!

@mwouts
Copy link
Owner

mwouts commented Oct 13, 2021

Hi @connerCpowell , thank you for reaching out.

Maybe a quick checklist to understand what is ongoing could be the following

  1. Do you see a notebook icon for .py or .md files in Jupyter? Yes => the Jupytext contents manager is active No => it is not active and thus Jupyter cannot save notebooks as text files
  2. Do you see a mention of Jupytext in the Jupyter startup logs? Something like [I 10:28:31.646 LabApp] [Jupytext Server Extension] Changing NotebookApp.contents_manager_class from LargeFileManager to jupytext.TextFileContentsManager? If No, like seems to be the case here, then the Jupytext Server extension is not active (and this explains why the contents manager is not active)
  3. Do you see any Jupytext configuration file in the paths listed by jupyter --paths? At Extension not loading in jupyterlab 3 #713 we have seen a case where the configuration files are installed at a location that is not found by Jupyter. How did you install Jupyter? If you used pip install --user then you might have to move these config files.

Also, I think it is a good idea indeed to have a virtual env (or a conda env) dedicated to Jupyter + Jupytext (and put the other packages in other envs, the ones you will use in the kernels). Personally I use conda, so I create a jupyter env with

mamba env create --file environment.yml  # replace mamba with conda if you don't have mamba

where environment.yml is just made of

name: jupyter
channels:
  - defaults
  - conda-forge
dependencies:
  - jupyterlab
  - toml
  - jupytext

and after that I run

conda activate jupyter
jupyter lab

@connerCpowell
Copy link
Author

Hi @mwouts, thank you so much for your response!

  1. No - .py / .md files only show icons for Editor / Editor or Markdown Preview; I guess my content manager isn't working properly
  2. No - It appears that the jupytext Server extension isn't active
  3. No - Below is my output:

(env38) pukowski@pukowski:~/sandbox/proj1$ jupyter --paths
config:
/home/pukowski/.jupyter
/home/pukowski/sandbox/proj1/env38/etc/jupyter
/usr/local/etc/jupyter
/etc/jupyter
data:
/home/pukowski/.local/share/jupyter
/home/pukowski/sandbox/proj1/env38/share/jupyter
/usr/local/share/jupyter
/usr/share/jupyter
runtime:
/home/pukowski/.local/share/jupyter/runtime

After reviewing, Extension not loading in jupyterlab 3 #713
I was able to fix this error with the following line of code:
cp -r $HOME/.local/etc/jupyter/* $HOME/.jupyter/

As you mentioned, it was an of the configuration files being installed at a location that was not found by Jupyter.

Thank you very much for your time & for pointing me in the right direction!

@mwouts
Copy link
Owner

mwouts commented Oct 14, 2021

Great news! Thanks for keeping us posted.

By the way, this kind of problem is expected to disappear with the next version of jupyter_core (version 4.9.0)

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

No branches or pull requests

2 participants