I just got two days worth of work vanished because jupyter notebook was not able to save (_xsrf argument missing).
I browse the internet for solutions:
looking at the running directory in jupyter
looking at the saved version in jupyter (there are none in my case)
I am starting to look at the chrome logs to at least see everything I typed but they are binary. Would you know where I could find logs of everything that was typed on chrome ? Or any other solution to retrieve that code ? You would be my savior !
I had the same issue and was able to recover all of my code from the 'history.sqlite' file in the following directory: ~/.ipython/profile_default/
(on Windows it's C:/Users/USERNAME/.ipython/profile_default/history.sqlite).
This is a file that saves all commands that were issued to the IPython kernel. At the end of the file (opened in a text editor) I found my most recent commands from the Jupyter notebook. This will only work if you did actually run your code though, not if it was just written.
Some more information is on the website where I found this solution: https://medium.com/flatiron-engineering/recovering-from-a-jupyter-disaster-27401677aeeb
Related
I want to view the jupyter notebook in without having to execute, I mean no to open it and iteratively execute commands, just to see it as if it were a pdf or something like that.
I ask this because every time a want to see some code in the notebook I have to go to the specific directory and run the comand jupyter notebook and wait until it starts to be able to open the proper file.
If you are using Macos, give this a shot
Found in this thread:
A way to quick preview .ipynb files
You can view it nicely in PyCharm as well.
You can convert your notebook to html (or other formats) via
File -> Download as -> html
You can see them dropping the file on VSCode too.
It must be very simple, but somehow I am missing something... Apologies for the long message but it's driving me crazy.
I'm reading thinkstat2, a free pdf about statistics for data science (beginner level).
It comes with exercises so I'm trying to follow the instructions and import the data. I'll describe the steps I'm following and give the pages, it's like a 2 minutes read.
Step 1a: Page 8 - "0.2 Using the code" - Get the code from author's github. I don't have a github account, so I dl the code as a zip on my hard drive. Then I extracted the content in a new folder.
Step 1b: Page 9 - Author suggests to get anaconda. From my understanding, anaconda contains many different app you can use through the "anaconda navigator". I have anaconda and will use Jupyter notebook for this.
Step 2: Page 9 - Author asks to run "nsfg.py" from his zip to make sure the reader has all the packages installed. Author says I should have a confirmation message. When I run it, there's a flash of command screen without any error or confirmation message. But if it's all about checking that the right package are installed correctly, I can just add "import x" in my code to add the missing package, so not a real issue here (or so I believed). I moved on.
Step 3: Pages 24 to 26 - "1.3 Importing the data" and "1.4 Dataframes" - This is where I'm stuck. After running "nsfg.py" (I mentioned in step 2), the author asks to "import nsfg", which is his own package created from "nsfg.py"? Maybe? So I try to import it and it's not recognized. Which probably comes from that "not a real issue" in step 2... I checked inside "nsfg.py" and it seems to be code to clean and read a .dct and .gz file.
Questions:
I don't understand what I'm supposed to do to make "nsfg.py" run properly.
I don't understand how my jupyter notebook would understand the "import nsfg" since those lies on my hard drive. The author does not add any line regarding importing anything from a local drive, or from a url to his github (not in the code of nsfg.py as well, except if I missed it).
I thought about just copy pasting the code of "nsfg.py" and running it, but I believe it would not work since the .dct and .gz file mentioned are saved locally as well. So I don't get how the code pasted from nsfg.py I run on jupyter notebook would make a link with those local .dct and .gz files. My python is not advanced enough to tinker that manually...
Help :( (any alternative solution is welcome)
Two ways to solve this, both worked for me:
Firstly, to replicate what the extracts of the book say, all assuming you are using linux or mac:
Hit git clone https://github.com/AllenDowney/ThinkStats2.git in your terminal in whatever folder you want to wok in
Then cd ThinkStats2/code.
Then python nsfg.py
Then hit python again to give you an interactive shell which is what the author of the book appears to be using - note the >>> before each command which indicates that it isn't in a Jupyter notebook.
To get this to work in a Jupyter notebook:
Hit git clone https://github.com/AllenDowney/ThinkStats2.git in your terminal in whatever folder you want to wok in
In your jupyter notebook interface, create a new notebook in the same directory as the ThinkStats2/code folder.
In the notebook hit import nsfg.
I think you are probably getting errors because you are not running your notebook from the same directory as the nsfg.py file which means that python can't find the script and so can't import it.
Lately, I've been running some Jupyter notebooks in VS Code, and I've been encountering a strange issue: whenever I open such a file, I am bombarded with pop-ups that look like this:
Sometimes a few will pop up; other times it can be upwards of 10 pop-ups. What's bizarre about this is that I already have my VS Code set up properly, and I can run my Jupyter notebooks just fine. I've tried selecting the 'Modify' option and going with the default selections just to make it go away, but no dice. How do I prevent these annoying pop-ups?
Per your new comments, can you check your default settings to see which application is targeted to open .ipynb files? Perhaps .ipynb files are linked to open (strangely) via the Setup exe.
If I close an instance of Jupyter QtConsole, and open a new instance, hit the Up key. Then the previous command I last ran is loaded.
In which directory is the past command history saved?
I've looked through the source on Github but haven't managed to find this. Nor does it appear to be in any path in jupyter --paths.
Going through the source the call stack is like:
HistoryConsoleWidget.history_previous()
HistoryConsoleWidget._get_edited_history()
HistoryConsoleWidget._set_history()
JupyterWidget._handle_history_reply()
Can't find anything further, so thought this might be a Jupyter thing. Googling this lead me to Where is the history file for ipython, and indeed it is stored at ~/.ipython/profile_default/history.sqlite.
I'm starting to work more with Jupyter notebooks, and am really starting to like it. However, I find it difficult to use it with my particular setup.
I have a workstation for running all the notebooks, but for a large part of my day I'm on-the-go with a space-constrained laptop with no power outlets. I'd like to be able to edit (but not run) these notebooks without installing and running the full Jupyter server backend, which I imagine would suck up a lot of power.
My question is: Is it possible for me to edit (and not run) notebooks without running the Jupyter server?
You could use one of the following options
1. ipynb-py-convert
With this module you can do a conversion from .py to .ipynb and vice-versa:
ipynb-py-convert ~/name_of_notebook.ipynb ~/name_of_notebook.py
where according to the documentation the cells are left as they are. To get back a jupyter notebook
ipynb-py-convert ~/name_of_notebook.py ~/name_of_notebook.ipynb
2. Ipython
However, you could also do a conversion to .py when you want to work it with an editor like VS Code or Sublime Text after you have download your .ipynb file with ipython:
ipython nbconvert --to python name_of_your_notebook.ipynb
As I was asking this question, I had opened the notebook locally in Visual Studio Code, but the preview was just the raw text representation of the notebook, so I had assumed that it needed the backend to run.
However, I was about to press submit on the question when I checked back in on it, and the notebook showed up just fine. So one solution is to open it in VS Code and wait a little bit.