Unable to open old notebook in conda environment OSError(22,'Invalid argument')

I had an old conda environment and had some jupyter notebooks from ~6 months ago, and I am now unable to open them. Here is the jupyter console output from my attempt

[W 22:08:54.661 NotebookApp] 400 GET /api/contents/Course%20Materials/06_pandas/06_lecture_script.ipynb?type=notebook&=1628712534135 (::1): Unreadable Notebook: c:\temp\06_lecture_script.ipynb OSError(22, ‘Invalid argument’)
[W 22:08:54.661 NotebookApp] Unreadable Notebook: C:\temp\06_lecture_script.ipynb OSError(22, ‘Invalid argument’)
[W 22:08:54.675 NotebookApp] 400 GET /api/contents/temp/06_lecture_script.ipynb?type=notebook&
=1628712534135 (::1) 25.000000ms referer=http://localhost:8888/notebooks/temp/06_pandas/06_lecture_script.ipynb

Things I have tried:

  • Creating new notebooks. This works fine, indicating that I am not having kernel issues
  • Creating a new conda environment with the below commands. I was able to open jupyter independently of my first environment, but hit the same error when opening old notebooks:
    conda create -n jupyter python=3.7
    conda activate jupyter
    conda install jupyter

The various stackoverflow searches that I have done for this error were with kernel issues, and jupyter was unable to start, and I do not have this problem. In particular, I have verified the following packages:

# Name                    Version                   Build  Channel
ipykernel                 6.0.3            py37h7813e69_0    conda-forge
ipython                   7.26.0           py37h4038f58_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.6.3              pyhd3deb0d_0    conda-forge

I can provide a full list of conda packages on request as well.

The searches I’ve done using ‘OSError(22, ‘Invalid argument’) windows’ suggest that it is a path issue.
In other words, what you are pointing at during your attempts at opening the notebook isn’t actually where that file is on your drive.
And there does seem to be a mismatch between:

/api/contents/Course%20Materials/06_pandas/06_lecture_script.ipynb

and

c:\temp\06_lecture_script.ipynb

and

notebooks/temp/06_pandas/06_lecture_script.ipynb

Not having access to your system, it is a bit hard to diagnose. (And have you tried using the full, absolute path when you are trying to get the other notebook to open or are you relying on a relative path? If OneDrive is involved, see the last paragraph below.)

However, I think you’ll sort it out, or at least understand better what may be going on, if you sort of hack through to get this particular notebook, 06_lecture_script.ipynb, working again. You say you can make new notebooks, right? If you make a new notebook and save it and quit Jupyter, can you also reopen it and it works? If so, make a new notebook file, save it with nothing really in it, and note where you save it on your drive. Quit Jupyter again. Now I’m going to suggest using Windows file navigator and a text editor (see options here; importantly, do not use anything with Microsoft in the name unless it is Visual Studio Code, commonly called VSCode, which is on that list) to swap the content of new notebook with the content of your old notebook, 06_lecture_script.ipynb. And that way when you open the new notebook again, you can try running the equivalent of your old notebook. To do this you’ll open the directories with the two different notebooks from your drive using the windows file navigator. (This alone may make you realize the notebook isn’t where you are pointing at.) Once you have the directories open, use your text editor to open each notebook file. It will be json text you’ll see. Now copy the old notebook text to your clipboard and replace the newer notebook’s content with it. Using the text editor, save the newer notebook with the old content now and close your text editor. Go back to Jupyter and try opening the ‘new’ notebook. Hopefully you now see the old content and it works. And if it works, hopefully you can either point correctly at the old notebooks or just move them to where they need to be in Windows file navigator to get things working again.

If what I suggest above doesn’t seem to be working or agree with what you are experiencing…
Do you happen to be using OneDrive? I keep seeing that this causes files to be in places that users didn’t realize they now were, see here and posts after that one discussing this and solutions.

Thank you very much. I was able to get the path resolved, and it turned out to be a OneDrive issue.

In case other people running onedrive run into something similar, there is a setting in Onedrive to Always keep on this device. Similar to the linked thread, Onedrive had decided to have a shallow copy on the device to save me disk space. Once I resynced, the old files worked fine.

1 Like