Ipython Notebook Running only as root - ipython

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.

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.

I just had a similar problem.
Attached beneath are my error message.
[E 19:32:53.893 NotebookApp] Unhandled error in API request
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/notebook/base/handlers.py", line 436, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 870, in run
value = future.result()
File "/usr/local/lib/python2.7/site-packages/tornado/concurrent.py", line 215, in result
raise_exc_info(self._exc_info)
File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 230, in wrapper
yielded = next(result)
File "/usr/local/lib/python2.7/site-packages/notebook/services/contents/handlers.py", line 126, in get
path=path, type=type, format=format, content=content,
File "/usr/local/lib/python2.7/site-packages/notebook/services/contents/filemanager.py", line 350, in get
model = self._notebook_model(path, content=content)
File "/usr/local/lib/python2.7/site-packages/notebook/services/contents/filemanager.py", line 310, in _notebook_model
self.mark_trusted_cells(nb, path)
File "/usr/local/lib/python2.7/site-packages/notebook/services/contents/manager.py", line 447, in mark_trusted_cells
trusted = self.notary.check_signature(nb)
File "/usr/local/lib/python2.7/site-packages/nbformat/sign.py", line 220, in check_signature
if self.db is None:
File "/usr/local/lib/python2.7/site-packages/traitlets/traitlets.py", line 439, in __get__
value = self._validate(obj, dynamic_default())
File "/usr/local/lib/python2.7/site-packages/nbformat/sign.py", line 127, in _db_default
self.init_db(db)
File "/usr/local/lib/python2.7/site-packages/nbformat/sign.py", line 139, in init_db
)""")
DatabaseError: database disk image is malformed
[E 19:32:53.895 NotebookApp] {
"Accept-Language": "en,zh-CN;q=0.8,zh;q=0.6,zh-TW;q=0.4,fr;q=0.2,es;q=0.2",
"Accept-Encoding": "gzip, deflate, sdch",
"Connection": "keep-alive",
"Accept": "application/json, text/javascript, */*; q=0.01",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36",
"Host": "localhost:8888",
"Referer": "http://localhost:8888/notebooks/trajectory_analysis.ipynb",
"X-Requested-With": "XMLHttpRequest"
}
I solved it by removing a file: nbsignatures.db.
Because the location of Jupyter on OSX is system-dependent, first locate the file using:
jupyter --data-dir
Then, remove the nbsignatures.db in it.
Reference: DatabaseError: database disk image is malformed #9293.

Related

How to enable code completation on jupyter?

I'm experiencing a very strange problem.
The code completetion is not working on my jupyter.
I have installed it at least 3 times, two manually and the last one via Anaconda.
I tried to use it on Chrome and Edge with no sucess.
I'm using it on Windows 10
Here goes the startup messages
[W 09:48:06.701 LabApp] Error loading server extension jupyter_nbextensions_configurator
Traceback (most recent call last):
File "C:\Anaconda3\envs\tf\lib\site-packages\notebook\notebookapp.py", line 1942, in init_server_extensions
mod = importlib.import_module(modulename)
File "C:\Anaconda3\envs\tf\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'jupyter_nbextensions_configurator'
[W 09:48:06.704 LabApp] Error loading server extension jupyter_tabnine
Traceback (most recent call last):
File "C:\Anaconda3\envs\tf\lib\site-packages\notebook\notebookapp.py", line 1942, in init_server_extensions
mod = importlib.import_module(modulename)
File "C:\Anaconda3\envs\tf\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'jupyter_tabnine'
[I 09:48:07.134 LabApp] JupyterLab extension loaded from C:\Anaconda3\envs\tf\lib\site-packages\jupyterlab
[I 09:48:07.135 LabApp] JupyterLab application directory is C:\Anaconda3\envs\tf\share\jupyter\lab
[I 09:48:07.142 LabApp] Serving notebooks from local directory: D:\Dev\Bolsa\src
[I 09:48:07.142 LabApp] Jupyter Notebook 6.1.4 is running at:
[I 09:48:07.143 LabApp] http://localhost:8888/?token=315a13e878a473d4f11f55f0d623240071060f151731429d
[I 09:48:07.144 LabApp] or http://127.0.0.1:8888/?token=315a13e878a473d4f11f55f0d623240071060f151731429d
[I 09:48:07.145 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 09:48:07.284 LabApp]
As you can see it is trying to load tabnine and jupyter_nbextensions_configurator, I'd installed it on the first jupyter installation, and I don't know why after two new jupyter installations and uninstall both of them jupyter still trying to load it.
Does anyone have any idea of what is happening?
Thanks
I could not find a solution for this problem, but I found a workaround.
I'd install the Python extension on VScode and then I'd open the jupyter notebook in there. So the code completation is working like a charm.
Here goes the instructions to open jupyter notebook on VSCode
https://code.visualstudio.com/docs/python/jupyter-support

Why am I getting a read-only file system from github and an error when trying to install apache airflow?

I am working on VirtualBox 6.0 with Python 3.5. I am trying to install airflow from github using the requirements-python3.5.txt file (https://raw.githubusercontent.com/apache/airflow/v1-10-stable/requirements/requirements-python3.5.txt). However, when I try to download this file from the command line, I get a read-only file system:
vagrant#learnairflow:~$ source .sandbox/bin/activate
(.sandbox) vagrant#learnairflow:~$ wget https://raw.githubusercontent.com/apache/airflow/v1-10-stable/requirements/requirements-python3.5.txt
--2020-06-13 15:47:54-- https://raw.githubusercontent.com/apache/airflow/v1-10-stable/requirements/requirements-python3.5.txt
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 199.232.48.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|199.232.48.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6210 (6.1K) [text/plain]
requirements-python3.5.txt: Read-only file system
Cannot write to ‘requirements-python3.5.txt’ (Success).
Subsequently, when I try to install airflow I get the following error:
(.sandbox) vagrant#learnairflow:~$ pip install "apache-airflow[celery, crypto, mysql, rabbitmq, redis]"==1.10.10 --constraint requirements-python3.5.txt
WARNING: The directory '/home/vagrant/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
ERROR: Exception:
Traceback (most recent call last):
File "/home/vagrant/.sandbox/lib/python3.5/site-packages/pip/_internal/cli/base_command.py", line 188, in _main
status = self.run(options, args)
File "/home/vagrant/.sandbox/lib/python3.5/site-packages/pip/_internal/cli/req_command.py", line 185, in wrapper
return func(self, options, args)
File "/home/vagrant/.sandbox/lib/python3.5/site-packages/pip/_internal/commands/install.py", line 288, in run
wheel_cache = WheelCache(options.cache_dir, options.format_control)
File "/home/vagrant/.sandbox/lib/python3.5/site-packages/pip/_internal/cache.py", line 296, in __init__
self._ephem_cache = EphemWheelCache(format_control)
File "/home/vagrant/.sandbox/lib/python3.5/site-packages/pip/_internal/cache.py", line 265, in __init__
globally_managed=True,
File "/home/vagrant/.sandbox/lib/python3.5/site-packages/pip/_internal/utils/temp_dir.py", line 137, in __init__
path = self._create(kind)
File "/home/vagrant/.sandbox/lib/python3.5/site-packages/pip/_internal/utils/temp_dir.py", line 185, in _create
tempfile.mkdtemp(prefix="pip-{}-".format(kind))
File "/usr/local/lib/python3.5/tempfile.py", line 358, in mkdtemp
prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir)
File "/usr/local/lib/python3.5/tempfile.py", line 130, in _sanitize_params
dir = gettempdir()
File "/usr/local/lib/python3.5/tempfile.py", line 296, in gettempdir
tempdir = _get_default_tempdir()
File "/usr/local/lib/python3.5/tempfile.py", line 231, in _get_default_tempdir
dirlist)
FileNotFoundError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/home/vagrant']
I've tried using the sudo command but it doesn't work either. Do you have any idea of what might be causing this error and how to fix it? Thank you in advance!

PyOrient client reports protocol version error when trying to connect to server

I'm getting what appears to be a version mismatch error from client.connect() when using what I believe to be the most recent versions of pyorient and the orientdb server
Protocol version 37 is not supported yet by this client.
Is there a more up-to-date version of pyclient available?
here's the test script
#!/usr/bin/env python
import pyorient
client = pyorient.OrientDB( "localhost", 2424 )
session_id = client.connect( "root", "password" )
Here's the full traceback
Traceback (most recent call last):
File "./test1.py", line 7, in <module>
session_id = client.connect( "root", "D1sOri3nted" )
File "~/.local/lib/python2.7/site-packages/pyorient-1.5.5-py2.7.egg/pyorient/orient.py", line 325, in connect
return self.get_message("ConnectMessage") \
File "~/.local/lib/python2.7/site-packages/pyorient-1.5.5-py2.7.egg/pyorient/orient.py", line 540, in get_message
message_instance = _Message(self._connection)\
File "~/.local/lib/python2.7/site-packages/pyorient-1.5.5-py2.7.egg/pyorient/messages/connection.py", line 17, in __init__
super( ConnectMessage, self ).__init__(_orient_socket)
File "~/.local/lib/python2.7/site-packages/pyorient-1.5.5-py2.7.egg/pyorient/messages/base.py", line 24, in __init__
sock.get_connection()
File "~/.local/lib/python2.7/site-packages/pyorient-1.5.5-py2.7.egg/pyorient/orient.py", line 78, in get_connection
self.connect()
File "~/.local/lib/python2.7/site-packages/pyorient-1.5.5-py2.7.egg/pyorient/orient.py", line 103, in connect
" is not supported yet by this client.", [])
pyorient.exceptions.PyOrientWrongProtocolVersionException: Protocol version 37 is not supported yet by this client.
I'm using the pyorient version from https://github.com/orientechnologies/pyorient
The server comes from the distributed docker image.
I'm uncertain of how to get the server version, but from within the docker container the console reports v3.0.1
Thanks in advance for any help or advice on this!

OSError: [Errno 99] Cannot assign requested address

Trying to run jupyter notebook on a CentOS 7. It comes back with:
OSError: [Errno 99] Cannot assign requested address
And the stack trace:
[user#desktop ~]$ jupyter notebook
Traceback (most recent call last):
File "/home/use/anaconda3/bin/jupyter-notebook", line 6, in <module>
sys.exit(notebook.notebookapp.main())
File "/home/user/anaconda3/lib/python3.6/site-packages/jupyter_core/application.py", line 267, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/home/user/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/home/user/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/home/user/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 1296, in initialize
self.init_webapp()
File "/home/user/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 1120, in init_webapp
self.http_server.listen(port, self.ip)
File "/home/user/anaconda3/lib/python3.6/site-packages/tornado/tcpserver.py", line 142, in listen
sockets = bind_sockets(port, address=address)
File "/home/user/anaconda3/lib/python3.6/site-packages/tornado/netutil.py", line 197, in bind_sockets
sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address
jupyter notebook --ip=127.0.0.1 --port=8888
I had to simply set the ip/port params. The issue was likely caused because the default ip/port that it was previously trying to assign was already taken!
In a remote VM, I solved the issue by
$ jupyter-notebook --ip=0.0.0.0 --port=8888
...
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://0.0.0.0:8888/?token=1234567890abcdefghijklmnopqrstuvwxyz (the token is for demo)
...
Note: do not assign the specific ip
then I can connect to jupyter notebook via:
http://your_vm_ip:8888/?token=1234567890abcdefghijklmnopqrstuvwxyz
(replace 0.0.0.0 with your_vm_ip)
Here is a permanent solution.
Create a configuration file for Jupyter, enter in the terminal: jupyter notebook --generate-config
The last command will create a file in /home/USER/.jupyter/jupyter_notebook_config.py
Open the file jupyter_notebook_config.py and edit the variable c.NotebookApp.ip as follows:
# c.NotebookApp.ip = 'localhost'
c.NotebookApp.ip = '127.0.0.1'
Enter in the terminal: jupyter notebook
Remarks: sometimes need to first chmod to grant permissions, the file
If you've tried several ports already (using --port XXXX), and none work:
Check that the localhost entry in /etc/hosts/ is not set to something other than 127.0.0.1.

I am using jupyter notebook, ipython 3 on windows. Whenever i am starting my python 3, i get the "Kernel Dead" message

Dead kernel
The kernel has died, and the automatic restart has failed. It is possible the kernel cannot be restarted.
If you are not able to restart the kernel, you will still be able to save the notebook, but running code will no longer work until the notebook is reopened.
the above message is shown in notebook dashboard after i start python3.
[I 23:07:08.365 NotebookApp] KernelRestarter: restarting kernel (4/5)
WARNING:root:kernel 9938cea3-6528-4a27-b4c3-ee906d748bfb restarted
Traceback (most recent call last):
File "c:\users\dharini\appdata\local\programs\python\python35-32\lib\runpy.py"
, line 170, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\dharini\appdata\local\programs\python\python35-32\lib\runpy.py"
, line 85, in _run_code
exec(code, run_globals)
File "c:\users\dharini\appdata\local\programs\python\python35-32\lib\site-pack
ages\ipykernel\__main__.py", line 3, in <module>
app.launch_new_instance()
File "c:\users\dharini\appdata\local\programs\python\python35-32\lib\site-pack
ages\traitlets\config\application.py", line 588, in launch_instance
app.initialize(argv)
File "<decorator-gen-123>", line 2, in initialize
File "c:\users\dharini\appdata\local\programs\python\python35-32\lib\site-pack
ages\traitlets\config\application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "c:\users\dharini\appdata\local\programs\python\python35-32\lib\site-pack
ages\ipykernel\kernelapp.py", line 417, in initialize
self.init_io()
File "c:\users\dharini\appdata\local\programs\python\python35-32\lib\site-pack
ages\ipykernel\kernelapp.py", line 316, in init_io
self.patch_io()
File "c:\users\dharini\appdata\local\programs\python\python35-32\lib\site-pack
ages\ipykernel\kernelapp.py", line 326, in patch_io
faulthandler_register = faulthandler.register
AttributeError: module 'faulthandler' has no attribute 'register'
[W 23:07:11.369 NotebookApp] KernelRestarter: restart failed
[W 23:07:11.369 NotebookApp] Kernel 9938cea3-6528-4a27-b4c3-ee906d748bfb died, r
emoving from map.
ERROR:root:kernel 9938cea3-6528-4a27-b4c3-ee906d748bfb restarted failed!
[W 23:07:11.390 NotebookApp] Kernel deleted before session
[W 23:07:11.392 NotebookApp] 410 DELETE /api/sessions/1cca4919-305f-4b4f-acdd-b2
a614fd2638 (::1) 3.00ms referer=http://localhost:8888/notebooks/Untitled.ipynb?k
ernel_name=python3
In command prompt i get the above shown message. What is the problem in the faulthandler module. How should I rectify it? I installed jupyter notebook by using "pip". I am new to python programming and also jupyter. please help me resolve this.
We accidentally made a release of the ipykernel package which doesn't work on Python 3.5 on Windows. Once we realised this, we made a new release (version 4.3.1) to fix it.
You can upgrade by running:
pip install --upgrade ipykernel
If you had installed ipykernel using conda, the command would be:
conda update ipykernel