Issue
I'm trying to run a simple Jupyter notebook on my local machine and I strangely run into some errors.
$ python --version
Python 3.11.5
I just run the following command:
$jupyter notebook
and when I select the available notebooks, I get a 500 Error and in the console I see the following:
ImportError: cannot import name 'contextfilter' from 'jinja2' (/home/joesan/.local/lib/python3.8/site-packages/jinja2/__init__.py)
I tried to install and uninstall jinja2 but to no avail. How can I fix this?
Additional Info:
$ 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)
I'm using pyenv to manage environments:
$ pyenv versions
system
3.8.0
* 3.11.5 (set by /home/joesan/.pyenv/version)
Solution
Have a look at this error:
ImportError: cannot import name 'contextfilter' from 'jinja2' (/home/joesan/.local/lib/python3.8/site-packages/jinja2/__init__.py)
It refers to jinja2
from Python 3.8, while your Python version is 3.11. I am guessing jupyter
is not installed in your Python 3.11 environment, but it is anyway present on the PATH
of your operating system. Since now we have this weird mix of 3.8 and 3.11, you encounter import errors.
Solution:
- Make sure you have isolated environments
- Install
jupyter
to your 3.11
Answered By - Lukasz Tracewski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.