ipython: Cannot open or create new Jupyter notebooks
I recently freshly installed Ubuntu 14.04 on my laptop, and installed IPython 4 through anaconda. However, I cannot open or load any notebooks, including those that open fine on my desktop. When I try to load a notebook, I get the following error: An unknown error occurred while loading this notebook. This version can load notebook formats v4 or earlier. See the server log for details.
The terminal gives:
Unhandled error in API request
Traceback (most recent call last):
File "/home/ryan/anaconda3/lib/python3.5/site-packages/traitlets/traitlets.py", line 432, in __get__
value = obj._trait_values[self.name]
KeyError: 'db'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ryan/anaconda3/lib/python3.5/site-packages/notebook/base/handlers.py", line 436, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "/home/ryan/anaconda3/lib/python3.5/site-packages/tornado/gen.py", line 870, in run
value = future.result()
File "/home/ryan/anaconda3/lib/python3.5/site-packages/tornado/concurrent.py", line 215, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/home/ryan/anaconda3/lib/python3.5/site-packages/tornado/gen.py", line 230, in wrapper
yielded = next(result)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/notebook/services/contents/handlers.py", line 126, in get
path=path, type=type, format=format, content=content,
File "/home/ryan/anaconda3/lib/python3.5/site-packages/notebook/services/contents/filemanager.py", line 350, in get
model = self._notebook_model(path, content=content)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/notebook/services/contents/filemanager.py", line 310, in _notebook_model
self.mark_trusted_cells(nb, path)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/notebook/services/contents/manager.py", line 447, in mark_trusted_cells
trusted = self.notary.check_signature(nb)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/nbformat/sign.py", line 220, in check_signature
if self.db is None:
File "/home/ryan/anaconda3/lib/python3.5/site-packages/traitlets/traitlets.py", line 439, in __get__
value = self._validate(obj, dynamic_default())
File "/home/ryan/anaconda3/lib/python3.5/site-packages/nbformat/sign.py", line 126, in _db_default
db = sqlite3.connect(self.db_file, **kwargs)
sqlite3.OperationalError: unable to open database file
When I try to create a new notebook, I get another error that says, Unexpected error while saving file: Dropbox/iPython Notebooks/Untitled.ipynb [Errno 13] Permission denied: '/home/ryan/.local/share/jupyter/notebook_secret'
This seems more informative, but I am relatively new to Linux/python/all this stuff.
The terminal gives:
Error while saving file: Dropbox/iPython Notebooks/Untitled.ipynb [Errno 13] Permission denied: '/home/ryan/.local/share/jupyter/notebook_secret'
Traceback (most recent call last):
File "/home/ryan/anaconda3/lib/python3.5/site-packages/traitlets/traitlets.py", line 432, in __get__
value = obj._trait_values[self.name]
KeyError: 'secret'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ryan/anaconda3/lib/python3.5/site-packages/notebook/services/contents/filemanager.py", line 387, in save
self.check_and_sign(nb, path)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/notebook/services/contents/manager.py", line 431, in check_and_sign
self.notary.sign(nb)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/nbformat/sign.py", line 245, in sign
signature = self.compute_signature(nb)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/nbformat/sign.py", line 195, in compute_signature
hmac = HMAC(self.secret, digestmod=self.digestmod)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/traitlets/traitlets.py", line 439, in __get__
value = self._validate(obj, dynamic_default())
File "/home/ryan/anaconda3/lib/python3.5/site-packages/nbformat/sign.py", line 173, in _secret_default
self._write_secret_file(secret)
File "/home/ryan/anaconda3/lib/python3.5/site-packages/nbformat/sign.py", line 179, in _write_secret_file
with io.open(self.secret_file, 'wb') as f:
PermissionError: [Errno 13] Permission denied: '/home/ryan/.local/share/jupyter/notebook_secret'
It was suggested that I include the output of python -c "import IPython; print(IPython.sys_info())"
, so here it is:
{'commit_hash': 'f534027',
'commit_source': 'installation',
'default_encoding': 'UTF-8',
'ipython_path': '/home/ryan/anaconda3/lib/python3.5/site-packages/IPython',
'ipython_version': '4.0.0',
'os_name': 'posix',
'platform': 'Linux-3.19.0-33-generic-x86_64-with-debian-jessie-sid',
'sys_executable': '/home/ryan/anaconda3/bin/python',
'sys_platform': 'linux',
'sys_version': '3.5.0 |Anaconda 2.4.0 (64-bit)| (default, Oct 19 2015, '
'21:57:25) \n'
'[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]'}
As mentioned, I’m not an expert at computing issues. I hope I am not doing something dumb. I have tried uninstalling and reinstalling anaconda, different versions of python, restarting the computer, and I have also tried the solutions found here https://github.com/ipython/ipython/issues/2097 and here https://github.com/ipython/ipython/issues/8294 as they seem similar.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 33 (6 by maintainers)
I solved this problem by changing the ownership of the ~/.local/share/jupyter directory from root to user. I don’t know why this problem occurred, as it didn’t happen on my other systems, so perhaps it’s a bug and I will leave this here.
I used “sudo” before “jupyter notebook --ip 0.0.0.0”, and it worked for me.
The better solution is to fix the permissions so that Jupyter can run in your regular user account. It’s hard to give precise instructions for this, because there are different things that can go wrong and cause similar errors. But in general, you will want to do something like this:
/home/username
on Linux, or/Users/username
on Mac), these instructions apply. If it’s somewhere else, the problem might be different.cd
to the folder containing that file.ls -l
to see all the files there. If the file is there, you’ll probably see that its owner isroot
, instead of your own username. This is the most common problem. If the file is not there, it probably can’t create it - go up a level and try the same thing on the directory.sudo chown username:username filename
to change the owner (and group) of the file to your own user. If you’re doing this on a directory, use the-R
flag to also change all the files inside it.You can also probably do this from a file manager, but there are loads of different ones, so we won’t give instructions.
how do you change the ownership of jupyter notebook though?
Maybe I should have clarified better. I am a windows user and I used my normal command line
so not sure if this will solve the problem for everyone. I had this same error and none of the solutions worked for me. I check the path to where jupyter was stored using the juypter --path. there will be a list of paths classified by config, data, and runtime. I cd into a path under config, looked like this c:\users\dn.user\appdata\local\programs\python\python37\etc\jupyter after changing directory to here I run jupyter again and no error. hope this helps someone
this command works for me: cd ~ && sudo chown username:username .local/share/ remember to replace username with your own username
It’s better to
chown
that folder to be owned by your user. Usingchmod 777
means any user can read or write it. We do store some secret information there, like the database used to track trusted notebooks.Check the permissions of
~/.ipython
, and trysudo chown username:username ~/ipython
, check also that:in particular that the first column start with
drwx
if it’s not you’ll need tosudo chmod o+w ~/.ipython
likely. Whereo+w
means add Write permission to Owner.