Can't Open .ipynb file in Jupyter: Too Large

  • Thread starter WWGD
  • Start date
  • Tags
    File
In summary: Notepad++ which should automatically split the long lines for you.in Thonny and Thonny shuts down each time ( 3 times so far).Unless you have a Jupyter plugin for Notepad++ it would be better to change the extension to .json, then you should get code folding which will help you.Notepad++ should be able to handle a 90Mb file without too much difficulty.Unless the file is corrupted there is no need to search manually, any code folding editor will quickly separate the wheat from the chaff.And are not accessible from the Windows file manager.Unless you have a Jupyter plugin for Not
  • #1
WWGD
Science Advisor
Gold Member
7,420
11,424
Hi All,
I may have asked this question earlier. Apologies if I did.

I have a Python .ipynb file in a Jupyter Notebook whose size is 99.3 MB. Thing is most of it is not code:
I wrote some code; specifically a loop incorrectly and it iterated way too many times. I saved the file, which included this repeated loop. Now I just get "File failed to load" error messages. Someone suggested ( it may have been here in PF) to change the extension to some text file, open it and delete the repeated output. But I don't see how to do this .
Any ideas?
 
Technology news on Phys.org
  • #2
Change the .ipynb extension to .txt and open it with notepad++.
 
Last edited:
  • Like
Likes WWGD
  • #3
Borg said:
Change the .ipynb extension to .txt and item or with notepad++.
Thank you, I thought of that, but I am not sure of how to do it. The format of the notebook does not seem to allow for that. These files seem to be stored in the back end server of Jupyter. Edit: And are not accessible from the Windows file manager.Maybe I can use save as and store them in a path. using the .txt extension. Will give it a try.
 
Last edited:
  • #4
Sorry about the typo earlier (phone autocorrect). Notepad++ should be able to handle a 90Mb file without too much difficulty. BTW, you don't really have to even change the extension - just open it directly with Notepad++.

Once you open it, the notebook is just a JSON file when you open it. Notepad++ will show the line numbers on the left side and should highlight an entire section when you click in it. Just look for one that's really big. When you remove the extra junk, you'll have to make sure that it's still well-formed json when you're done - no dangling brackets like this { that don't have the ending bracket (or vice versa). I would advise two things with this:
  • Practice on manually removing content from a smaller file first to make sure that it opens when you're finished.
  • Make a backup of the file that you're trying to fix and only do this to copies of the original.
 
  • Like
Likes WWGD
  • #5
WWGD said:
I have a Python .ipynb file in a Jupyter Notebook whose size is 99.3 MB. Thing is most of it is not code:
I wrote some code; specifically a loop incorrectly and it iterated way too many times. I saved the file, which included this repeated loop.
Why do you want to open this file? Searching manually through a 99.3 MB seems like looking for a needle in an array of haystacks.
 
  • Like
Likes WWGD and Vanadium 50
  • #6
nbstripout was made for this task.

If you want to do it manually:

WWGD said:
Thank you, I thought of that, but I am not sure of how to do it. The format of the notebook does not seem to allow for that. These files seem to be stored in the back end server of Jupyter.
No, the 'back end server of Jupyter' just stores them in the file system, wherever you tell it to, defaulting to your home directory which on Windows is something like C:\Users\WWGD. Don't you recognise the path when you browse files from the Jupyter window?

WWGD said:
Edit: And are not accessible from the Windows file manager.
Either you are looking in the wrong place or you have some daft setting in File Manager. If it is the first, type
Code:
cd C:\
dir *.ipynb /S
and wait to find all the notebooks on your C: drive (and repeat for other drives if necessary).

WWGD said:
Maybe I can use save as and store them in a path. using the .txt extension. Will give it a try.
Unless you have a Jupyter plugin for Notepad++ it would be better to change the extension to .json, then you should get code folding which will help you. If you do have a Jupyter plugin then just leave the extension.
 
  • Like
Likes WWGD
  • #7
Mark44 said:
Why do you want to open this file? Searching manually through a 99.3 MB seems like looking for a needle in an array of haystacks.
Unless the file is corrupted there is no need to search manually, any code folding editor will quickly separate the wheat from the chaff.
 
  • Like
Likes WWGD and Borg
  • #8
Mark44 said:
Why do you want to open this file? Searching manually through a 99.3 MB seems like looking for a needle in an array of haystacks.
A Ctrl +F should help.
 
  • #9
Now, I found the file path ( Indeed in C:\Users\...) I've tried to open the file ( With a .pdf extension) , in Thonny and Thonny shuts down each time ( 3 times so far).
 
  • #10
WWGD said:
Now, I found the file path ( Indeed in C:\Users\...) I've tried to open the file ( With a .pdf extension)
If it has a pdf extension it is probably a pdf file, not a Jupyter notebook.

WWGD said:
in Thonny and Thonny shuts down each time ( 3 times so far).
Ditch Thonny, you need a proper code editor. For most purposes I recomment Visual Studio Code, but it barfs on really big files so for this purpose on Windows I would use Notepad++. But it won't be any use for a pdf file, that is not going to contain your code.
 
  • Like
Likes WWGD
  • #11
pbuk said:
If it has a pdf extension it is probably a pdf file, not a Jupyter notebook.Ditch Thonny, you need a proper code editor. For most purposes I recomment Visual Studio Code, but it barfs on really big files so for this purpose on Windows I would use Notepad++. But it won't be any use for a pdf file, that is not going to contain your code.
Thanks; will try resaving as a .ipynb and see if I can open it.
 
  • #12
This short script will strip the outputs from a Jupyter notebook (and will run as a Jupyter notebook itself).

Strip output from Jupyter notebook:
import json

# Enter your filename here.
filename = 'your-file-name-without-extension'

ext = '.ipynb'
outfilename = filename + '-stripped'

# Parse the notebook file into a dict and reference its 'cells'.
infile = open(filename + ext)
notebook = json.load(infile)
infile.close()

cells = notebook['cells']

print('Removing output from', len(cells), 'cells')
for cell in cells:
    if 'outputs' in cell:
        cell['outputs'] = []

# Dump the modified dict as prettyprinted json (= ipynb).
print('Writing to', outfilename + ext)
outfile = open(outfilename + ext, 'w')
json.dump(obj, outfile, indent = 2)
outfile.close()
 
  • Like
Likes Borg and WWGD
  • #13
Thanks, @pbuk , just a follow-up. It worked well. Thanks again.
 
  • Love
Likes pbuk

FAQ: Can't Open .ipynb file in Jupyter: Too Large

Why am I unable to open .ipynb files in Jupyter?

There could be several reasons why you are unable to open .ipynb files in Jupyter. One possible reason could be that the file is too large or contains too much data for Jupyter to handle. Another reason could be that there is a compatibility issue between the file and your version of Jupyter.

How can I fix the issue of not being able to open .ipynb files in Jupyter?

If the file is too large, you can try reducing its size by removing unnecessary data or splitting it into smaller files. You can also try upgrading to a newer version of Jupyter to see if it resolves any compatibility issues. Another option is to use a different software or tool that can handle larger .ipynb files.

Is there a limit to the size of .ipynb files that Jupyter can open?

Yes, there is a limit to the size of .ipynb files that Jupyter can handle. This limit can vary depending on your system's specifications and the version of Jupyter you are using. If your file exceeds this limit, you may encounter the error message "Too Large" when trying to open it.

Can I increase the size limit for .ipynb files in Jupyter?

Yes, it is possible to increase the size limit for .ipynb files in Jupyter. However, this may require making changes to your system's settings or the Jupyter configuration. It is recommended to consult the Jupyter documentation or seek assistance from a technical expert before attempting to modify the size limit.

Are there any alternatives to Jupyter for working with large .ipynb files?

Yes, there are other tools and software that can handle large .ipynb files. Some popular alternatives to Jupyter include PyCharm, VS Code, and Google Colab. These tools offer similar functionalities and may have a higher size limit for .ipynb files. It is worth trying out different options to see which one works best for your specific needs.

Back
Top