Score:0

Jupyter Notebook not working with WSL

jp flag

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!

BeastOfCaerbannog avatar
ca flag
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.).
kathmcp avatar
jp flag
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!
BeastOfCaerbannog avatar
ca flag
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 avatar
ca flag
BTW, Miniconda is an excellent tool for managing Python environments and packages! ;)
kathmcp avatar
jp flag
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 avatar
jp flag
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 avatar
jp flag
I also had to reinstall numpy and pandas in Ubuntu using "pip3 install pandas" and "pip3 install numpy", and finally it all worked :)
BeastOfCaerbannog avatar
ca flag
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](https://askubuntu.com/help/whats-reputation). 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?](https://askubuntu.com/help/how-to-answer) Thanks!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.