Why did my notebook switch from Python to a text file?

For some reason a jupyter notebook I created in python with code and markdown opened as a text file. I have created dozens of notebooks with code and markdown and this hasn’t happened.

Is it possible to open it as I created it or did I do something that won’t allow that?
If so, how do I do this? Thanks!

If it saved completely without an issue, you should be able to open it still, eventually.
Open Jupyter up like you would make a new file and then select to open that one from inside Jupyter. Does that work? If not, check the extension is .ipynb.
Is it just this notebook? Do others that you have open as expected?

If all the content is in there it should be fixable, even if something happened. (You usually can tell in the text editor if most of the content is actually still there, even if you cannot fully read it because it is encoded.) It just becomes how easy is it fixable. Sometimes it is just a matter of pasting the bulk of the content into the backbone of an empty one.

You’d have to share more information to know what direction to take next. Or how it could have happened.

For some context…
Jupyter .ipynb files have always been text files. They are special json formatted text with the code and output (usually) stored in them. You have always been able to choose to open them in a text editor, however, it won’t be easily managed that way to make major changes or to easily move things around or to another notebook.

I closed jupyter and reopened Jupyter notebook from Anaconda. Still did the same but, It says its a pynb not ipynb file. All of my other files save and open properly. This file was opened and looked and appeared to be proper earlier today, then I reopened it and it was coded.

How would a file change format from ipnyb to pynb? Is it possible to change it back? Thanks!!!

THIS IS WHAT IT LOOKS LIKE

WHEREAS, this is what all my other notebooks look like. I have no clue howit would have changed file types. I tried to save as ipnyb but it reverts back to pynb

If you mean that it is for example Notebook.pynb rather than Notebook.ipynb you need to rename it. You can rename files using right click menu from the tree view or by clicking on the name.

1 Like

Your system doesn’t have anything set up for opening .pynb file types, and so it opens it with a text editor.

The small part of the screenshot you shared looks like a normal part of a normal .ipynb file. That’s the good news.

It reverting when you try to rename it is odd. Do you have other machines available? If it is only modestly sized document, you can go here and click the ‘launch binder’ badge and open a Jupyter session on a temporary remote machine. When the session comes up, drag-and-drop your file from your local machine into the file navigator pane on the left side of the Jupyter session. Release the mouse button of the drag and drop when the gray box around the pane appears. It should upload to the temporary session, and you should be able to rename it there and test if you can open it. If you make something useful, download it back to your local machine in a different locaiton in your file directory hierarchy for safe measure and try it now.

I can open it on my surface. Should I open it in Anaconda/Jupyter lab or elsewhere? Bizarre this has happened only to one of my notebooks, right?

All of my notebooks have been opened started and saved as notebookX.ipynb. This one had previously opened properly.

Whoa - i just right clicked it from the tree, renamed it. added the “i” and that worked.

So bizarre.! Thanks for walk me through this!!!

2 Likes