Python Jupyter Notebook 500:内部服务器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36851746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jupyter Notebook 500 : Internal Server Error
提问by user1551817
I want to learn how to use Jupyter Notebook. So far, I have managed to download and install it (using pip), but I'm having trouble opening it.
我想学习如何使用 Jupyter Notebook。到目前为止,我已经设法下载并安装了它(使用 pip),但是我无法打开它。
I am opening it by typing:
我通过键入打开它:
jupyter notebook
in my terminal. It opens in my browser, with the URL:
在我的终端。它在我的浏览器中打开,网址为:
http://localhost:8888/tree
and I just get a big:
我得到了一个很大的:
500 : Internal Server Error
message. Could someone point me in the right direction of what's going wrong please?
信息。有人可以指出我出了什么问题的正确方向吗?
The full error message in my terminal:
我的终端中的完整错误消息:
[E 17:53:52.034 NotebookApp] Uncaught exception GET /tree (::1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/tree', version='HTTP/1.1', remote_ip='::1', headers={'Accept-Language': 'en-US,en;q=0.8,es;q=0.6', 'Accept-Encoding': 'gzip, deflate, sdch', 'Host': 'localhost:8888', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1'})
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/web.py", line 1443, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/web.py", line 2800, in wrapper
return method(self, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/notebook/tree/handlers.py", line 50, in get
terminals_available=self.settings['terminals_available'],
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/notebook/base/handlers.py", line 302, in render_template
template = self.get_template(name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/notebook/base/handlers.py", line 298, in get_template
return self.settings['jinja2_env'].get_template(name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 719, in get_template
return self._load_template(name, self.make_globals(globals))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 693, in _load_template
template = self.loader.load(self, name, globals)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/loaders.py", line 127, in load
code = environment.compile(source, name, filename)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 493, in compile
self.handle_exception(exc_info, source_hint=source)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/notebook/templates/tree.html", line 8, in template
data-base-url="{{base_url | urlencode}}"
TemplateAssertionError: no filter named 'urlencode'
[E 17:53:52.819 NotebookApp] {
"Accept-Language": "en-US,en;q=0.8,es;q=0.6",
"Accept-Encoding": "gzip, deflate, sdch",
"Host": "localhost:8888",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1"
}
[E 17:53:52.819 NotebookApp] 500 GET /tree (::1) 874.29ms referer=None
EDIT
编辑
When attempting to update ipython as advised, the following error message was produced:
尝试按照建议更新 ipython 时,产生了以下错误消息:
Exception:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 732, in install
**kwargs
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 835, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 1030, in move_wheel_files
isolated=self.isolated,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/wheel.py", line 247, in move_wheel_files
prefix=prefix,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/locations.py", line 142, in distutils_scheme
i = d.get_command_obj('install', create=True)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 845, in get_command_obj
klass = self.get_command_class(command)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/dist.py", line 430, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2229, in load
return self.resolve()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named command.install
回答by Ehab AlBadawy
Was having a similar problem. Fixed it after upgrading ipython with this command
遇到了类似的问题。使用此命令升级 ipython 后修复它
sudo pip install --upgrade "ipython[all]"
sudo pip install --upgrade "ipython[all]"
Note: make sure to type ipython with double quotes and [all]
注意:确保输入带有双引号的 ipython 和 [all]
回答by kruger
try upgrading jupyter hub first
首先尝试升级 jupyter hub
pip install --upgrade jupyterhub
pip install --upgrade --user nbconvert
worked for me on windows 10 as well.
在 Windows 10 上也为我工作。
回答by f.c
Works for me by upgrade the nbconvert package. pip install --upgrade --user nbconvert
通过升级 nbconvert 包对我有用。 pip install --upgrade --user nbconvert
回答by Isopycnal Oscillation
After trying all the solutions on this page without success, a variation of @kruger answer is what worked for me, simply this:
在尝试了此页面上的所有解决方案都没有成功之后,@kruger 答案的变体对我有用,简单地说:
pip install --upgrade nbconvert
pip install --upgrade nbconvert
回答by scanny
I also encountered this problem. The root cause in my case was that I already had Jinja2 installed with root permissions (having used sudo pip install
before I knew better).
我也遇到了这个问题。在我的案例中,根本原因是我已经安装了具有 root 权限的 Jinja2(sudo pip install
在我知道更好之前使用过)。
My solution was to uninstall Jinja2 with sudo pip uninstall
(which was required because it was installed with root permissions), and re-run pip install jupyter
to reinstall it with regular user permissions.
我的解决方案是卸载 Jinja2 sudo pip uninstall
(这是必需的,因为它是使用 root 权限安装的),然后重新运行pip install jupyter
以使用常规用户权限重新安装它。
$ sudo pip uninstall Jinja2
$ pip install jupyter
While using sudo
to install works here, it makes the problem worse in the longer term because all its packages are installed with root permissions, leading to further problems like this in future with other packages. It's kind of like kicking that can down the road.
虽然使用sudo
to install 在这里工作,但从长远来看,它会使问题变得更糟,因为它的所有软件包都是以 root 权限安装的,这会导致将来其他软件包出现更多类似问题。这有点像在路上踢球。
Many won't care of course, as long as it works. But for those that do I thought I'd mention.
许多人当然不会在意,只要它有效。但对于那些我想我会提到的人。
There's no way to know for sure what the offending package is, but it's likely to be one of those in the stack trace. I noticed Jinja2 as one I vaguely remembered from my early days in Python so I started there and it worked.
没有办法确定有问题的包是什么,但它很可能是堆栈跟踪中的包之一。我注意到 Jinja2 是我在 Python 早期依稀记得的一个,所以我从那里开始并且它起作用了。
回答by Solomon Vimal
A simple solution that worked for me: on the terminal, run the following command -
一个对我有用的简单解决方案:在终端上,运行以下命令 -
jupyter troubleshoot | grep jupyter | grep /
This will list the path to the different versions of jupyter that are installed in your computer. Try all the versions one by one and delete the binaries of the ones that give you the 500 error. Then you might want to change the link to jupyter by adding a line (alias jupyter="/usr/local/bin/jupyter") to your ~/.bashrc file or call jupyter with the absolute path.
这将列出计算机中安装的不同版本的 jupyter 的路径。一一尝试所有版本并删除那些给你 500 错误的二进制文件。然后,您可能希望通过在 ~/.bashrc 文件中添加一行(别名 jupyter="/usr/local/bin/jupyter")或使用绝对路径调用 jupyter 来更改指向 jupyter 的链接。
Note:this is not the cleanest solution, but one that works.
注意:这不是最干净的解决方案,而是一种有效的解决方案。
回答by Gihan Samarasinghe
I had this issue as of 22/03/2019, and what worked for me was updating conda and then upgrading jupyter using pip:
截至 2019 年 3 月 22 日,我遇到了这个问题,对我有用的是更新 conda,然后使用 pip 升级 jupyter:
conda update --all
pip install jupyter --upgrade
回答by Hadis Bagherpour
I had the same problem and was a bit painful until I managed to fix it. The magic line the worked for me was
我遇到了同样的问题,在我设法修复它之前有点痛苦。对我有用的魔线是
conda install -c conda-forge jupyter_contrib_nbextensions
回答by Madhuparna Bhowmik
This error is due to inconsistencies. Updating jupyter solves the issue.
Use the following command if you are using Anaconda-
conda update jupyter
此错误是由于不一致造成的。更新 jupyter 解决了这个问题。如果您使用的是 Anaconda,请使用以下命令-
conda update jupyter
回答by maikelo
I had the same problem and my solution was update the Jinja2 package to version Jinja2-2.8.
我遇到了同样的问题,我的解决方案是将 Jinja2 包更新到 Jinja2-2.8 版本。
To update it I used the easy_install command as follow:
为了更新它,我使用了 easy_install 命令,如下所示:
sudo easy_install -U python-jinja2[all]
After that the 500 : Internal Server Errorwas fixed.
之后500 : Internal Server Error被修复。