pythonpython-3.xubuntujupyter-notebook

Cannot run Jupyter Notebook on Ubuntu 22.04


I have Ubuntu 22.04 with python 3.10. When I try to open jupyter notebook from terminal this error occurrs:

Traceback (most recent call last):
  File "/home/anaconda3/lib/python3.10/site-packages/notebook/services/sessions/sessionmanager.py", line 9, in <module>
    import sqlite3
  File "/home/anaconda3/lib/python3.10/sqlite3/__init__.py", line 57, in <module>
    from sqlite3.dbapi2 import *
  File "/home/anaconda3/lib/python3.10/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: /home/anaconda3/lib/python3.10/lib-dynload/_sqlite3.cpython-310-x86_64-linux-gnu.so: undefined symbol: sqlite3_trace_v2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/anaconda3/bin/jupyter-notebook", line 5, in <module>
    from notebook.notebookapp import main
  File "/home/anaconda3/lib/python3.10/site-packages/notebook/notebookapp.py", line 83, in <module>
    from .services.sessions.sessionmanager import SessionManager
  File "/home/anaconda3/lib/python3.10/site-packages/notebook/services/sessions/sessionmanager.py", line 12, in <module>
    from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'

When I checked sqlite3, it is intalled in home/anaconda3/lib/python3.10/sqlite3/ and it contains dbapi2.py. Should I somehow reorganize the folders? PS: When I tried pip install pysqlite2 another error occurred: ERROR: Could not find a version that satisfies the requirement pysqlite2 (from versions: none) ERROR: No matching distribution found for pysqlite2


Solution

  • It looks like you performed a manual installation of Jupyter (and required dependencies) directly in your home directory. I'm assuming /home/anaconda3/ is your home directory, and anaconda3 is just a badly chosen name.

    Rename the lib subdirectory:

    mv lib lib_aside
    

    You might want to do something similar for include/ or bin/ directories directly in your home as well (but check first what is in bin/ ; if that is all Python/Jupyter related, or that there's software you actually need that is not default installable).

    Comment out any PYTHONPATH setting in your .bashrc that points to that lib/ directory (and subdirectories).

    Comment out any PATH alteration to the bin/ in your home directory as well.

    If you don't need it, comment-out the section with Conda stuff as well.

    Install Jupyter from your package manager. E.g.

    sudo apt install python3-notebook
    

    Start a new terminal, and test:

    which python
    which jupyter
    

    These should point to /usr/bin

    Start your notebook:

    jupyter notebook