0

I have installed Windows Subsystem for Linux 2 on my windows computer, and using Ubuntu, have been accessing Jupyter Notebook. This has now stopped working. When I open Ubuntu and type in jupyter notebook it used to give me a link which I copied into Microsoft Edge. I am now getting the following error message.

kathmcp02@DESKTOP-Q2SS990:~$ jupyter notebook
Traceback (most recent call last):
  File "/home/kathmcp02/.local/bin/jupyter-notebook", line 5, in <module>
    from notebook.notebookapp import main
  File "/home/kathmcp02/.local/lib/python3.8/site-packages/notebook/notebookapp.py", line 44, in <module>
    from jinja2 import Environment, FileSystemLoader
ImportError: cannot import name 'Environment' from 'jinja2' (/home/kathmcp02/.local/lib/python3.8/site-packages/jinja2/__init__.py)
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 32, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 12, in <module>
    import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket
  File "/usr/lib/python3/dist-packages/requests_unixsocket/__init__.py", line 4, in <module>
    from .adapters import UnixAdapter
  File "/usr/lib/python3/dist-packages/requests_unixsocket/adapters.py", line 3, in <module>
    from requests.adapters import HTTPAdapter
ImportError: cannot import name 'HTTPAdapter' from 'requests.adapters' (/home/kathmcp02/.local/lib/python3.8/site-packages/requests/adapters.py)

Original exception was: Traceback (most recent call last): File "/home/kathmcp02/.local/bin/jupyter-notebook", line 5, in <module> from notebook.notebookapp import main File "/home/kathmcp02/.local/lib/python3.8/site-packages/notebook/notebookapp.py", line 44, in <module> from jinja2 import Environment, FileSystemLoader ImportError: cannot import name 'Environment' from 'jinja2' (/home/kathmcp02/.local/lib/python3.8/site-packages/jinja2/init.py)

I am not very computer savvy, so any help would be much appreciated. Thank you!

muru
  • 197,895
  • 55
  • 485
  • 740
  • 1
    Have a look at this issue: https://github.com/jupyter/notebook/issues/3332 It looks like a user solved a similar problem by downgrading the jinja2 package, so it may be worth trying to downgrade it too. Mind that the issue I linked above is 2 years old, so you may not have to necessarily downgrade jinja2 to the mentioned version. Downgrading depends on how you installed jinja2, so I cannot give you the exact command, unless you provide more info about your Python installation and the package manager you are using (e.g pip, conda, etc.). – BeastOfCaerbannog Jul 14 '21 at 09:59
  • Thank you so much for your advice. I have managed to solve it, but I had to uninstall the WSL, Ubuntu and all the related packages, and then I reinstalled it all using Miniconda3, and so far it seems to be working again. Thanks again! – kathmcp Jul 15 '21 at 10:06
  • That's great! Would you be so kind and add an answer with the steps you took to solve your problem, so that other users having the same problem would be able to solve it too? – BeastOfCaerbannog Jul 15 '21 at 10:08
  • BTW, Miniconda is an excellent tool for managing Python environments and packages! ;) – BeastOfCaerbannog Jul 15 '21 at 10:09
  • To uninstall the WSL and Ubuntu, I went to Control Panel, Programs, Turn Windows Features On and Off, then unticked Windows Subsystem for Linux, and restarted my computer. I thought this would uninstall everything to do with the WSL but when I went into the folder where the files were saved, Ubuntu was still there, so I deleted the Ubuntu folder, in C/Users.../AppData/Local/Packages/CanonicalGroupLimited...Ubuntu.... and restarted computer again. – kathmcp Jul 19 '21 at 09:41
  • Then I followed these instructions for reinstalling the WSL, Ubuntu and MiniConda3 https://towardsdatascience.com/configuring-jupyter-notebook-in-windows-subsystem-linux-wsl2-c757893e9d69. I also had to go to the Ubuntu directory in my profile folder right click on "LocalState", Properties, Advanced, deselect "Compress contents". – kathmcp Jul 19 '21 at 09:43
  • I also had to reinstall numpy and pandas in Ubuntu using "pip3 install pandas" and "pip3 install numpy", and finally it all worked :) – kathmcp Jul 19 '21 at 09:46
  • As Ask Ubuntu is a questions-answers site, and comments are only supposed to be used for asking for clarification and/or extra info, it would be perfect if you could add the above comments as an answer, which can be also upvoted (I will if you add it) and you can earn reputation points. Also make sure to add the important parts of a link in your answer, since if the link gets removed in the future, the answer won't be complete. Have a look in How do I write a good answer? Thanks! – BeastOfCaerbannog Jul 19 '21 at 11:56

0 Answers0