Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ipython Notebook Running only as root

I was trying to import a notebook in iPython(Jupyter after updating). But for some reason, I am able to import any notebook only if I run as root user. Otherwise, I get the following error for all notebooks.

An unknown error occurred while loading this notebook. This version can load notebook formats v4 or earlier. See the server log for details.

iPython3 notebook is able to load the notebooks though. Is there something that I can do to resolve this issue?

[W 23:04:29.100 NotebookApp] 404 GET /static/components/MathJax/config/Safe.js?rev=2.5.3 (127.0.0.1) 40.67ms referer=http://localhost:8889/notebooks/Challenges/German%20Credit%20Dataset%20Classification%20-%20Challenge%201/GermanCreditCardClassification.ipynb
[E 23:04:29.377 NotebookApp] Unhandled error in API request
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/notebook/base/handlers.py", line 436, in wrapper
        result = yield gen.maybe_future(method(self, *args, **kwargs))
      File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 870, in run
        value = future.result()
      File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 215, in result
        raise_exc_info(self._exc_info)
      File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 230, in wrapper
        yielded = next(result)
      File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/handlers.py", line 129, in get
        path=path, type=type, format=format, content=content,
      File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/filemanager.py", line 348, in get
        model = self._notebook_model(path, content=content)
      File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/filemanager.py", line 308, in _notebook_model
        self.mark_trusted_cells(nb, path)
      File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/manager.py", line 447, in mark_trusted_cells
        trusted = self.notary.check_signature(nb)
      File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 220, in check_signature
        if self.db is None:
      File "/usr/local/lib/python2.7/dist-packages/traitlets/traitlets.py", line 439, in __get__
        value = self._validate(obj, dynamic_default())
      File "/usr/local/lib/python2.7/dist-packages/nbformat/sign.py", line 126, in _db_default
        db = sqlite3.connect(self.db_file, **kwargs)
    OperationalError: unable to open database file
[E 23:04:29.389 NotebookApp] {
      "Accept-Language": "en-US,en;q=0.8", 
      "Accept-Encoding": "gzip, deflate, sdch", 
      "Connection": "keep-alive", 
      "Accept": "application/json, text/javascript, */*; q=0.01", 
      "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36", 
      "Dnt": "1", 
      "Host": "localhost:8889", 
      "X-Requested-With": "XMLHttpRequest", 
      "Referer": "http://localhost:8889/notebooks/Challenges/German%20Credit%20Dataset%20Classification%20-%20Challenge%201/GermanCreditCardClassification.ipynb"
    }
[E 23:04:29.390 NotebookApp] 500 GET /api/contents/Challenges/German%20Credit%20Dataset%20Classification%20-%20Challenge%201/GermanCreditCardClassification.ipynb?type=notebook&_=1449266668869 (127.0.0.1) 134.27ms referer=http://localhost:8889/notebooks/Challenges/German%20Credit%20Dataset%20Classification%20-%20Challenge%201/GermanCreditCardClassification.ipynb

Ipython Details Server Information:

You are using Jupyter notebook.

The version of the notebook server is 4.0.2 and is running on:
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2]

Current Kernel Information:

unable to contact kernel

OS: Linux Mint x64 running on 3.13.0-37-generic Kernel

Answer: KT.'s solution works. I think that I ran Jupyter as root the first time which caused the files to be inaccessible to non root users as mentioned by KT.

like image 948
nithishr Avatar asked Oct 28 '15 20:10

nithishr


1 Answers

OK, let me take a guess here.

When you ran ipython notebook for the first time it was under root. Consequently, some of the files that Jupyter uses were created as root-owned from the start. It is no surprise now that whenever you run Jupyter as a non-root user, he fails to write to those files which results in the errors that you see.

In the particular situation that you see in the log, Jupyter has problems writing to the nbsignatures.db SQLite database. This file should be located in Jupyter's DATA_DIR, which is normally something like ~/.local/share/jupyter.

If you do not have this directory, you can find it out by running ipython and doing this, for example:

In [1]: from jupyter_core.application import JupyterApp
In [2]: JupyterApp().data_dir
Out[2]: u'/home/ubuntu/.local/share/jupyter'

What you need to do now is to make sure that everything in that directory is owned by the correct user, not by root. This might mean doing something like

# chown -R <yourusername>.<yourusername> ~/.local/share/jupyter

as root.

like image 113
KT. Avatar answered Sep 20 '22 12:09

KT.