Problem creating jupyter notebook files with fresh JupyterLab install on Linux

I have had trouble locating any specific help with what appears to be an installation problem.

I installed Jupyter Lab using the recommended method of pip install jupyter-lab from jupyter.org.

System Details:

  • OS is Mint 20.3 Cinnamon
  • Browser is Chrome (v 103.0.5060.114)
  • Python is 3.8.10 (64bit)

After having issues when trying to open older notebook files I discovered I can’t even create a new file. All attempts respond with the following error:

Unexpected error while saving file: Downloads/Untitled.ipynb [Errno 2] No such file or directory: '/home/user/Notebooks/.~Untitled.ipynb' -> '/home/user/Notebooks/Untitled.ipynb'

A file of this name was created but opening the file in a text editor shows it to be empty. Nothing, not even initialization information, was written to it. I get the same error when I open an existing file from the same (or any other) directory.

I have tried the usual uninstalling and reinstalling as well as rebooting and cleaning out old preferences. Does anyone have an idea as to what may be wrong?

Additional Detail from running jupyter lab with the debugger after tapping the File → New → Notebook:

[I 2022-07-06 10:30:34.667 LabApp] Build is up to date
[I 2022-07-06 10:30:58.786 ServerApp] Creating new notebook in /Notebooks
[E 2022-07-06 10:30:58.803 ServerApp] Error while saving file: Notebooks/Untitled.ipynb [Errno 2] No such file or directory: '/home/user/Notebooks/.~Untitled.ipynb' -> '/home/user/Notebooks/Untitled.ipynb'
    Traceback (most recent call last):
      File "/home/user/.local/lib/python3.8/site-packages/jupyter_server/services/contents/fileio.py", line 112, in atomic_writing
        yield fileobj
      File "/home/user/.local/lib/python3.8/site-packages/jupyter_server/services/contents/fileio.py", line 210, in atomic_writing
        yield f
      File "/home/user/.local/lib/python3.8/site-packages/jupyter_server/services/contents/fileio.py", line 294, in _save_notebook
        nbformat.write(
      File "/home/user/.local/lib/python3.8/site-packages/nbformat/__init__.py", line 164, in write
        s = writes(nb, version, **kwargs)
      File "/home/user/.local/lib/python3.8/site-packages/nbformat/__init__.py", line 110, in writes
        return versions[version].writes_json(nb, **kwargs)
      File "/home/user/.local/lib/python3.8/site-packages/nbformat/v4/nbjson.py", line 56, in writes
        return json.dumps(nb, **kwargs)
      File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
        return cls(
    TypeError: __init__() got an unexpected keyword argument 'capture_validation_error'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/user/.local/lib/python3.8/site-packages/jupyter_server/services/contents/filemanager.py", line 435, in save
        self._save_notebook(os_path, nb, capture_validation_error=validation_error)
      File "/home/user/.local/lib/python3.8/site-packages/jupyter_server/services/contents/fileio.py", line 294, in _save_notebook
        nbformat.write(
      File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
        self.gen.throw(type, value, traceback)
      File "/home/user/.local/lib/python3.8/site-packages/jupyter_server/services/contents/fileio.py", line 210, in atomic_writing
        yield f
      File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
        self.gen.throw(type, value, traceback)
      File "/home/user/.local/lib/python3.8/site-packages/jupyter_server/services/contents/fileio.py", line 116, in atomic_writing
        replace_file(tmp_path, path)
      File "/home/user/.local/lib/python3.8/site-packages/jupyter_server/services/contents/fileio.py", line 24, in replace_file
        os.replace(src, dst)
    FileNotFoundError: [Errno 2] No such file or directory: '/home/user/Notebooks/.~Untitled.ipynb' -> '/home/user/Notebooks/Untitled.ipynb'
[W 2022-07-06 10:30:58.806 ServerApp] 500 POST /api/contents/Notebooks?1657117858764 (127.0.0.1): Unexpected error while saving file: Notebooks/Untitled.ipynb [Errno 2] No such file or directory: '/home/user/Notebooks/.~Untitled.ipynb' -> '/home/user/Notebooks/Untitled.ipynb'
[W 2022-07-06 10:30:58.807 ServerApp] Unexpected error while saving file: Notebooks/Untitled.ipynb [Errno 2] No such file or directory: '/home/user/Notebooks/.~Untitled.ipynb' -> '/home/user/Notebooks/Untitled.ipynb'
[E 2022-07-06 10:30:58.809 ServerApp] {
      "Host": "localhost:8888",
      "Accept": "*/*",
      "Referer": "http://localhost:8888/lab/tree/Notebooks",
      "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
    }
[E 2022-07-06 10:30:58.809 ServerApp] 500 POST /api/contents/Notebooks?1657117858764 (127.0.0.1) 25.68ms referer=http://localhost:8888/lab/tree/Notebooks

You could try doing a more persuasive update of the packages that might be at play (e.g. in the traceback, or closely related):

pip install --update jupyterlab jupyterlab_server jupyter_server traitlets nbformat

The output of pip freeze (before and after) might help more, to be sure.

The longer story: we try to keep all the metadata lined up, and test multiple versions, but there is very little solid underneath us: pip has changed its behavior several times in the last year. If reproducing this environment is important, it pays to use something like pip-tools to capture (and check in) a definition, and virtualenv to re-install and manage them.

1 Like

Thank you for your quick response. It worked.

Some additional details, in case it helps you debug or someone else with a similar issue:

Using pip install --upgrade ..., I got a long list of confirmations that I already for which I had up to date installations except for the following couple of messages toward the bottom:

Requirement already satisfied, skipping upgrade: async-generator in ./.local/lib/python3.8/site-packages (from nbclient>=0.5.0->nbconvert>=6.4.4->jupyter_server) (1.10)
Requirement already satisfied, skipping upgrade: pycparser in ./.local/lib/python3.8/site-packages (from cffi>=1.0.0->argon2-cffi->jupyter_server) (2.20)
ERROR: nbconvert 6.5.0 has requirement jinja2>=3.0, but you'll have jinja2 2.11.2 which is incompatible.
ERROR: nbconvert 6.5.0 has requirement jupyter-core>=4.7, but you'll have jupyter-core 4.6.3 which is incompatible.
ERROR: nbconvert 6.5.0 has requirement MarkupSafe>=2.0, but you'll have markupsafe 1.1.0 which is incompatible.
ERROR: jupyter-server 1.18.1 has requirement jupyter-core>=4.7.0, but you'll have jupyter-core 4.6.3 which is incompatible.
ERROR: jupyter-client 7.3.4 has requirement jupyter-core>=4.9.2, but you'll have jupyter-core 4.6.3 which is incompatible.
ERROR: jupyter-client 7.3.4 has requirement pyzmq>=23.0, but you'll have pyzmq 19.0.2 which is incompatible.
Installing collected packages: traitlets, fastjsonschema, nbformat
  Attempting uninstall: traitlets
    Found existing installation: traitlets 5.0.4
    Uninstalling traitlets-5.0.4:
      Successfully uninstalled traitlets-5.0.4
  Attempting uninstall: nbformat
    Found existing installation: nbformat 5.0.7
    Uninstalling nbformat-5.0.7:
      Successfully uninstalled nbformat-5.0.7
Successfully installed fastjsonschema-2.15.3 nbformat-5.4.0 traitlets-5.3.0

I then ran it again and got a different response (because the older things have been uninstalled):

Requirement already up-to-date: jupyterlab in ./.local/lib/python3.8/site-packages (3.4.3)
Requirement already up-to-date: jupyterlab_server in ./.local/lib/python3.8/site-packages (2.15.0)
Requirement already up-to-date: jupyter_server in ./.local/lib/python3.8/site-packages (1.18.1)
Requirement already up-to-date: traitlets in ./.local/lib/python3.8/site-packages (5.3.0)
Requirement already up-to-date: nbformat in ./.local/lib/python3.8/site-packages (5.4.0)
Requirement already satisfied, skipping upgrade: ipython in ./.local/lib/python3.8/site-packages (from jupyterlab) (7.18.1)
Requirement already satisfied, skipping upgrade: tornado>=6.1.0 in ./.local/lib/python3.8/site-packages (from jupyterlab) (6.2)
Requirement already satisfied, skipping upgrade: jupyter-core in ./.local/lib/python3.8/site-packages (from jupyterlab) (4.6.3)
... ***long list like this***

with no red ‘error’ flags

I launched jupyter lab again and new and older files worked as expected.