Rename failed - 'os_path' is not defined

After installing notebook (version 6.4.12) via pip on Windows 10, I ran the application using

python -m notebook

as per here, entered some basic content and code (all of which ran fine) and then attempted to rename my notebook. This failed, with the following error text:

Rename Failed
An error occurred while renaming "Untitled.ipynb" to "Introduction.ipynb".
Traceback (most recent call last): File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\tornado\", line 1704, in _execute result = await result File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\tornado\", line 234, in wrapper yielded = ctx_run(next, result) File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\notebook\services\contents\", line 135, in patch model = yield maybe_future(cm.update(model, path)) File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\notebook\services\contents\", line 296, in update self.rename(path, new_path) File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\notebook\services\contents\", line 284, in rename self.rename_file(old_path, new_path) File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\notebook\services\contents\", line 579, in rename_file raise web.HTTPError(400, f'Cannot rename file or directory {os_path!r}') NameError: name 'os_path' is not defined

What should I do in order to successfully rename my notebooks?


Looks like a bug in the error handling, os_path isn’t defined:

1 Like

I am also facing same issue . Commenting for subscription .
I have raised the issue on git too. check it out :issue_6458

1 Like

You closed the GitHub issue as “working fine now” - what did you do? I am still having this problem.

It seems ill -logical but what i did , just renamed the file in different environment , and retried to rename files in problematic env (new version of jupyter notebook), it started working .

There were two problems in my case:

  1. NameError, because os_path is not defined (you can replace it by old_path on the last line)
  2. The new path was considered hidden incorrectly, because self.root_dir was absolute and new_path was relative. In this case, pretty unfortunately, the new_path[len(self.root_dir)] expression was evaluating to .ipynb (incorrectly), and was considered hidden, so failed the second condition. You can be fixed by making sure all the paths are absolute.

To check if you’re facing the same issue, just add some extra letters in your new file name, and it will work.

1 Like