Convert from .py to .ipynb format

You most likely aren’t working in the correct directory in your notebook.

Note that I said this in my post:

You are using JupyterLab it appears. The file navigation panel on the left and the running notebook are not linked; just because you are looking at the target notebook you wish to convert in the panel on the left, doesn’t mean that is in the current working directory in your active notebook on the right. To check the current working directory in your active notebook, type the following in a cell in it and run it:

pwd

(By the way, that means ‘print working directory’. See my links and notes here if these concepts aren’t familiar to you.)

I suspect you’ll see it doesn’t match your location for the notebook you are trying to point Jupytext at for conversion. The way you have written your !jupytext command, it isn’t going to work until you can enter the following in the notebook cell and see the notebook you are hoping to convert among the list of files in the current working directory:

ls

So one solution is to specify the absolute path to that notebook in your !jupytext command. Right now you are relying on a relative path, in this case where the notebook file and the running notebook are expected to be in the same directory relative to each other.

Another possible solution is to close the notebook you currently show because jupytext is installed. And just start a new one from the launcher after you have navigated in the file navigation panel to the directory containing the target notebook you wish to convert. You should then see the new notebook get created in the same directory as the notebook you are targeting for conversion and now your !jupytext command.

I’ll add for the sake of improved completeness, that within the active notebook, it is also possible to change the working directory, see about the line magic command %cd here. You’d need to navigate relative or use an absolute path, as well.

Another possibility is to navigate to the directory with the notebook in the terminal launched from JupyterLab, and then run your jupytext command, but now without the exclamation mark as you are directly on the command line already.