0

Hello everyone: I am a university student and I regularly work in a jupyter notebook environment, within a WSL system in my computer.

All of a sudden, my jupyter notebook kernel "died" and it refused to start ever since: this is the traceback I get from the terminal.

Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/freddycch/.local/lib/python3.6/site-packages/ipykernel_launcher.py", line 16, in
app.launch_new_instance()
File "/home/freddycch/.local/lib/python3.6/site-packages/traitlets/config/application.py", line 663, in launch_instance
app.initialize(argv)
File "/home/freddycch/.local/lib/python3.6/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw)
File "/home/freddycch/.local/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/home/freddycch/.local/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 589, in initialize
self.init_kernel()
File "/home/freddycch/.local/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 452, in init_kernel
user_ns=self.user_ns,
File "/home/freddycch/.local/lib/python3.6/site-packages/traitlets/config/configurable.py", line 412, in instance
inst = cls(*args, **kwargs)
File "/home/freddycch/.local/lib/python3.6/site-packages/ipykernel/ipkernel.py", line 73, in init
kernel = self,
File "/home/freddycch/.local/lib/python3.6/site-packages/traitlets/config/configurable.py", line 412, in instance
inst = cls(*args, **kwargs)
File "/home/freddycch/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 661, in init
self.init_history()
File "/home/freddycch/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 1802, in init_history
self.history_manager = HistoryManager(shell=self, parent=self)
File "/home/freddycch/.local/lib/python3.6/site-packages/IPython/core/history.py", line 543, in init
self.new_session()
File "/home/freddycch/.local/lib/python3.6/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw)
File "/home/freddycch/.local/lib/python3.6/site-packages/IPython/core/history.py", line 58, in needs_sqlite
return f(self, *a, **kw)
File "/home/freddycch/.local/lib/python3.6/site-packages/IPython/core/history.py", line 569, in new_session
NULL, "") """, (datetime.datetime.now(),))
sqlite3.DatabaseError: database disk image is malformed

I am a physics student, thus I really don't know what to do in this situation. At this point, I have tried uninstalling and re-installing python, and I went full sudo apt purge to try and reset everything, without great results.

Is anyone able to help me fix this problem? Thank you in advance :D

FreddyCCH
  • 1
  • 1
  • "sqlite3.DatabaseError: database disk image is malformed" - I wouldn't go so far as to uninstall Python. I'd recommend writing a small function, outside of Jupyter, and try to connect to the database. Take small steps and work your way up. – duffymo Apr 21 '22 at 19:15
  • Thank you for your suggestion: how can I do that, though? When I open sqlite3 in my terminal and try the `pragma integrity_check;` command, I only get "ok" as a response; if I have to be really honest, I don't really know what this "bug" is about and I have just searched the web for similar error messages that have been solved. – FreddyCCH Apr 22 '22 at 14:37
  • Write a _main_ function that connects and queries the database. Run it on the command line in a terminal shell, outside of Jupyter: https://pynative.com/python-sqlite/ – duffymo Apr 22 '22 at 14:39
  • Thank you, I'll check this out and see what I can do! :D – FreddyCCH Apr 22 '22 at 14:40
  • Well, I have `sqlitebrowser` installed, and I guess the problem is in the `history.sqlite` database. I am looking at the database, but what am I supposed to fix now? I have never worked with something like this, I'm sorry >_> – FreddyCCH Apr 22 '22 at 15:00
  • Sorry, I don't understand. You have a problem connecting to SQL Lite with Python. I'm suggesting that you strip the problem down to its minimum and work your way up. No need for Jupyter to see if your code can work. I don't know what sqlitebrowser is. I thought Jupyter was running Python code for you. – duffymo Apr 22 '22 at 15:04
  • Technically speaking, I don't know what the problem is, *exactly*. The notebook starts, but its kernel does NOT start: the traceback is shown above. If I open the history.py file mentioned in the traceback, the database that seems to have issues is `history.sqlite`. sqlitebrowser is just a software, I can open the .sqlite file and look at its tables. Sadly, I really have no clue of what I am supposed to do to fix the problem, as it's the first time that I have to deal with this issue. – FreddyCCH Apr 22 '22 at 17:43
  • I have found the issue! If i go `pragma integrity_check;` with `history.sqlite` opened in the terminal I get the Error "database disk image is malformed". What do I do now? – FreddyCCH Apr 22 '22 at 17:50
  • Great work. It's a satisfying feeling to figure things out, as you well know. Next question: what to do about it? Where did your database disk image come from? What possibility do you have to fixing it? – duffymo Apr 22 '22 at 17:52
  • I really don't know how to fix the database, but I am figuring it out online. Thank you for your patience, I'll just tag you in the comments if I don't manage to fix it by myself. Technically speaking, I didn't even know what database I was supposed to look for, so... I guess it's a start. – FreddyCCH Apr 22 '22 at 17:54
  • SQLite 3 looks like the right thing. Where did you get it from? Start there. Good luck! – duffymo Apr 22 '22 at 17:55
  • I saw that sqlite was the problem and installed sqlitebrowser to open and edit the databases. At least, now I know what database is giving me issues and I can see what the error message is. Well, I'm stuck again. This time, I can show what I am doing: https://stackoverflow.com/questions/18259692/how-to-recover-a-corrupt-sqlite3-database/57872238#57872238 This is a similar discussion. None of the pieces of code provided in that link seem to be working at the moment, but I will figure out something. – FreddyCCH Apr 22 '22 at 19:15
  • Start at the beginning: where did you get this database file? – duffymo Apr 22 '22 at 19:57
  • The database file is in my `.ipython/profile_default` folder. When open it with sqlite3 and run `pragma integrity_check;` I get the following errors: 1) `on tree page 2 cell 0: invalid page number 9981`; (one error) 2) `on tree page 8594 cell 94: Rowid 878 out of order` (four errors); 3) `page 9980 is never used` (one error) If I do this: https://www.recoveryandmanagement.com/repair-sqlite-database-manually/ I fail at step #7 and get `Error in statement #2: not an error` - what now? ç_ç – FreddyCCH Apr 22 '22 at 20:51
  • Still don't see an answer: where did you get the database file from? Did you download it from the web? Create it yourself? Something send it to your machine on a network? The file is corrupt. How are you going to fix it? I'd start by going back to the source and asking for a fix. – duffymo Apr 22 '22 at 21:11
  • Ok, I did this: I created a new `.sqlite` database making use of the `.dump` command, and I am now using that new database as `history.sqlite`. The problem seems to have been solved, i.e. my notebook starts properly, but I really don't know what the occurring problem is in step #7 (see above). I am not ok with *not* fixing the database as I wanted, but the notebook environment works now :D – FreddyCCH Apr 22 '22 at 21:12
  • @duffymo the database `history.sqlite` is created by jupyter notebook and is updated with every "session", I guess. Something went wrong in a previous session, and stopped the notebook environment from working. The problem seems to be fixed now, but at this point I really don't know what went wrong in the first place ( i.e. I don't get the meaning of those error messages above, and I don't know how to fix them ) – FreddyCCH Apr 22 '22 at 21:16
  • What do you need a database for? I use Jupyter notebook. Never connected it to a SQL database. Why are you using it? I'd argue that it's not necessary, but I'm not certain of your use case. You're a physicist. What kind of problem are you solving? – duffymo Apr 22 '22 at 23:53

0 Answers0