jupyter notebook 404 error: file not found after server restart
Fixes a Jupyter 404 'file not found' after server restart: the server came back in a different working directory, or the file path changed. Check the server's root dir and reopen from the file browser. Not for 404s on the server URL itself.
TL;DR
A 404 on a notebook right after a server restart means the server is now serving a different directory than the one the browser tab remembers, or the file moved. Look at the URL path versus the server's startup directory. Restart the server from the original directory (or pass --notebook-dir=[original]), then reopen the notebook from the file browser instead of the stale tab.
jupyter notebook 404 error: file not found after server restartUse this when
- A previously working notebook URL 404s immediately after the server restarted.
- The file browser shows a different directory tree than before.
- The server was started from a different shell or by a different tool than last time.
Not for this skill when
- The server URL itself 404s. That is a proxy or base-url problem.
- The file is genuinely deleted. Check the trash or version control.
Steps
- Check where the server is rooted: look at the startup log line showing the serving directory. Verify: you know the current root.
- Compare with the 404 URL path. Verify: you can see the mismatch between the remembered path and the served tree.
- Restart the server from the original directory, or start with
--notebook-dir=[original-dir]. Verify: the startup log shows the right root. - Open the notebook fresh from the file browser, not the old tab. Verify: it loads without a 404.
- If you must keep the new root, move or copy the notebook into the served tree. Verify: the file browser lists it.
Variant phrasings
jupyter 404 after restart
Short form. Root directory mismatch is the cause.
notebook not found jupyter server restart
Symptom phrasing. Reopen from the file browser.
jupyter file browser wrong directory
The visible symptom. The server root moved.
Compatibility: notebook 6/7, JupyterLab 3/4. The --notebook-dir / --ServerApp.root_dir flag exists in all of them.
Why it happens
The browser tab remembers a full path like /notebooks/project/analysis.ipynb, but that path is relative to whatever directory the server was started in. Restart the server from your home directory instead of the project directory and the same URL now points at nothing. The file is fine; the server's idea of the filesystem root moved.
Edge cases / pitfalls
- Bookmarking notebook URLs bakes in the old root. Re-bookmark after fixing the root.
- JupyterHub spawners sometimes start in a different home directory after an upgrade. Check the spawner config, not just your memory.
- A 404 with a token in the URL can also mean the token changed on restart. Rule out the root-dir mismatch first; it is more common.
--notebook-diris deprecated in favor of--ServerApp.root_dirin new versions, but both still work. Use whichever your version accepts.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_RzrM5hY0vwyN2mS2KJtPUQ