Ipython 笔记本 运行 仅作为 root
Ipython Notebook Running only as root
我试图在 iPython(更新后的 Jupyter)中导入笔记本。但出于某种原因,只有当我 运行 作为 root 用户时,我才能导入任何笔记本。否则,所有笔记本都会出现以下错误。
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 可以加载笔记本。
我可以做些什么来解决这个问题吗?
[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 详情
服务器信息:
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 运行ning on 3.13.0-37-generic Kernel
答案:
KT. 的解决方案有效。我认为我 运行 Jupyter 第一次作为 root 用户,这导致非 root 用户无法访问文件,如 KT 所述。
好吧,我来猜一猜。
当你第一次 运行 ipython notebook
时,它在 root
下。因此,Jupyter 使用的一些文件从一开始就被创建为 root 拥有的。现在毫不奇怪,每当您 运行 Jupyter 作为非 root 用户时,他无法写入那些导致您看到的错误的文件。
在您在日志中看到的特定情况下,Jupyter 在写入 nbsignatures.db
SQLite 数据库时遇到问题。该文件应该位于 Jupyter 的 DATA_DIR
中,通常类似于 ~/.local/share/jupyter
.
如果你没有这个目录,你可以通过运行宁ipython
找到它,然后这样做,例如:
In [1]: from jupyter_core.application import JupyterApp
In [2]: JupyterApp().data_dir
Out[2]: u'/home/ubuntu/.local/share/jupyter'
您现在需要做的是确保该目录中的所有内容都属于正确的用户,而不是 root。这可能意味着做类似
的事情
# chown -R <yourusername>.<yourusername> ~/.local/share/jupyter
作为 root。
我刚刚遇到了类似的问题。
下面附上我的错误信息。
[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"
}
我通过删除一个文件解决了这个问题:nbsignatures.db.
因为 Jupyter 在 OSX 上的位置取决于系统,首先使用以下方法定位文件:
jupyter --data-dir
然后,去掉其中的nbsignatures.db。
我试图在 iPython(更新后的 Jupyter)中导入笔记本。但出于某种原因,只有当我 运行 作为 root 用户时,我才能导入任何笔记本。否则,所有笔记本都会出现以下错误。
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 可以加载笔记本。 我可以做些什么来解决这个问题吗?
[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 详情 服务器信息:
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 运行ning on 3.13.0-37-generic Kernel
答案: KT. 的解决方案有效。我认为我 运行 Jupyter 第一次作为 root 用户,这导致非 root 用户无法访问文件,如 KT 所述。
好吧,我来猜一猜。
当你第一次 运行 ipython notebook
时,它在 root
下。因此,Jupyter 使用的一些文件从一开始就被创建为 root 拥有的。现在毫不奇怪,每当您 运行 Jupyter 作为非 root 用户时,他无法写入那些导致您看到的错误的文件。
在您在日志中看到的特定情况下,Jupyter 在写入 nbsignatures.db
SQLite 数据库时遇到问题。该文件应该位于 Jupyter 的 DATA_DIR
中,通常类似于 ~/.local/share/jupyter
.
如果你没有这个目录,你可以通过运行宁ipython
找到它,然后这样做,例如:
In [1]: from jupyter_core.application import JupyterApp
In [2]: JupyterApp().data_dir
Out[2]: u'/home/ubuntu/.local/share/jupyter'
您现在需要做的是确保该目录中的所有内容都属于正确的用户,而不是 root。这可能意味着做类似
的事情# chown -R <yourusername>.<yourusername> ~/.local/share/jupyter
作为 root。
我刚刚遇到了类似的问题。 下面附上我的错误信息。
[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"
}
我通过删除一个文件解决了这个问题:nbsignatures.db.
因为 Jupyter 在 OSX 上的位置取决于系统,首先使用以下方法定位文件:
jupyter --data-dir
然后,去掉其中的nbsignatures.db。