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.
Related
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
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.
I just started using Python 3 on Jupyter so I'm not really confortable with it. When I open a file with some commands, if I try to run it, the screen will give me back errors saying that the variables are not defined.
If I try to run directly filename.find("2019") it gives an error back. So when I open a file should, as first step, run all the cells?
Yes, generally speaking, when you open an existing notebook and want to add some code to it at the end, you should first run all the existing cells. You can do this from the menu: Cell -> Run All. Otherwise you would have no proper way of testing your additional code, since it may depend on changes to the namespace in the preceding code.
If the notebook wasn't active so far in that Jupyter session, there is no need to restart the kernel. Jupyter starts a separate kernel instance for every notebook you open.
I was recently introduced to JupyterLab and I have seen this video from the documentation, where they introduce the synchronised "output view" of a cell:
https://youtu.be/Asa_ML45HP8
I wonder if it was possible to have "only" this output view as the result of executing a script. So that I could run a Python script, and a browser window would open up and I would see only the output view without the Jupyter interface itself.
Is this or something similar easily feasible already? E.g. by configuring JupyterLab in some way and then starting it?
If I wanted to write an application that does that, do you have hints on where to start from? I presume, that there is a lot of code already present that could be reused.