我正试图在本地机器上运行一个简单的Jupyter笔记本,但奇怪的是我遇到了一些错误.
$ python --version
Python 3.11.5
我只运行了以下命令:
$jupyter notebook
当我 Select 可用的笔记本时,我得到一个500错误,并在控制台中看到以下内容:
ImportError: cannot import name 'contextfilter' from 'jinja2' (/home/joesan/.local/lib/python3.8/site-packages/jinja2/__init__.py)
我试图安装和卸载JJIA2,但都无济于事.我怎么才能解决这个问题呢?
其他信息:
$ jupyter --version
Selected Jupyter core packages...
IPython : 7.27.0
ipykernel : 6.4.1
ipywidgets : 7.6.5
jupyter_client : 7.0.3
jupyter_core : 4.8.1
jupyter_server : not installed
jupyterlab : not installed
nbclient : 0.5.4
nbconvert : not installed
nbformat : 5.1.3
notebook : 6.4.4
qtconsole : 5.1.1
traitlets : 5.1.0
Opening in existing browser session.
libva error: /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so init failed
/usr/lib/python3.8/json/encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
return _iterencode(o, 0)
[E 19:20:53.073 NotebookApp] Uncaught exception GET /notebooks/boston_housing.ipynb (127.0.0.1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/boston_housing.ipynb', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
File "/home/joesan/.local/lib/python3.8/site-packages/tornado/web.py", line 1704, in _execute
result = await result
File "/home/joesan/.local/lib/python3.8/site-packages/tornado/gen.py", line 775, in run
yielded = self.gen.send(value)
File "/home/joesan/.local/lib/python3.8/site-packages/notebook/notebook/handlers.py", line 95, in get
self.write(self.render_template('notebook.html',
File "/home/joesan/.local/lib/python3.8/site-packages/notebook/base/handlers.py", line 516, in render_template
return template.render(**ns)
File "/home/joesan/.local/lib/python3.8/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/home/joesan/.local/lib/python3.8/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "/home/joesan/.local/lib/python3.8/site-packages/notebook/templates/notebook.html", line 1, in top-level template code
{% extends "page.html" %}
File "/home/joesan/.local/lib/python3.8/site-packages/notebook/templates/page.html", line 154, in top-level template code
{% block header %}
File "/home/joesan/.local/lib/python3.8/site-packages/notebook/templates/notebook.html", line 115, in block 'header'
{% for exporter in get_frontend_exporters() %}
File "/home/joesan/.local/lib/python3.8/site-packages/notebook/notebook/handlers.py", line 23, in get_frontend_exporters
from nbconvert.exporters.base import get_export_names, get_exporter
File "/home/joesan/.local/lib/python3.8/site-packages/nbconvert/__init__.py", line 4, in <module>
from .exporters import *
File "/home/joesan/.local/lib/python3.8/site-packages/nbconvert/exporters/__init__.py", line 3, in <module>
from .html import HTMLExporter
File "/home/joesan/.local/lib/python3.8/site-packages/nbconvert/exporters/html.py", line 14, in <module>
from jinja2 import contextfilter
ImportError: cannot import name 'contextfilter' from 'jinja2' (/home/joesan/.local/lib/python3.8/site-packages/jinja2/__init__.py)
我正在使用pyenv来管理环境:
$ pyenv versions
system
3.8.0
* 3.11.5 (set by /home/joesan/.pyenv/version)