Cannot run Jupyter Notebook on Ubuntu 22.04

huangapple go评论146阅读模式
英文:

Cannot run Jupyter Notebook on Ubuntu 22.04

问题

我有Ubuntu 22.04,安装了Python 3.10。当我尝试从终端打开Jupyter Notebook时,出现以下错误:

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'

当我检查sqlite3时,它安装在home/anaconda3/lib/python3.10/sqlite3/目录下,并包含dbapi2.py。我应该如何重新组织文件夹? PS:当我尝试执行pip install pysqlite2时,另一个错误发生:ERROR: Could not find a version that satisfies the requirement pysqlite2 (from versions: none) ERROR: No matching distribution found for pysqlite2

英文:

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 &quot;/home/anaconda3/lib/python3.10/site-packages/notebook/services/sessions/sessionmanager.py&quot;, line 9, in &lt;module&gt;
    import sqlite3
  File &quot;/home/anaconda3/lib/python3.10/sqlite3/__init__.py&quot;, line 57, in &lt;module&gt;
    from sqlite3.dbapi2 import *
  File &quot;/home/anaconda3/lib/python3.10/sqlite3/dbapi2.py&quot;, line 27, in &lt;module&gt;
    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 &quot;/home/anaconda3/bin/jupyter-notebook&quot;, line 5, in &lt;module&gt;
    from notebook.notebookapp import main
  File &quot;/home/anaconda3/lib/python3.10/site-packages/notebook/notebookapp.py&quot;, line 83, in &lt;module&gt;
    from .services.sessions.sessionmanager import SessionManager
  File &quot;/home/anaconda3/lib/python3.10/site-packages/notebook/services/sessions/sessionmanager.py&quot;, line 12, in &lt;module&gt;
    from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named &#39;pysqlite2&#39;

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

答案1

得分: 1

It looks like you performed a manual installation of Jupyter (and required dependencies) directly in your home directory.
我看起来你在你的主目录中手动安装了Jupyter(以及所需的依赖项)。

I'm assuming /home/anaconda3/ is your home directory, and anaconda3 is just a badly chosen name.
我假设/home/anaconda3/是你的主目录,而anaconda3只是一个选择不当的名称。

Rename the lib subdirectory:
重命名lib子目录:

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).
您可能还想在主目录中直接对include/或bin/目录执行类似的操作(但首先检查bin/中的内容;如果那些都与Python/Jupyter相关,或者有您实际需要但不是默认可安装的软件)。

Comment out any PYTHONPATH setting in your .bashrc that points to that lib/ directory (and subdirectories).
.bashrc中注释掉任何指向lib/目录(以及其子目录)的PYTHONPATH设置。

Comment out any PATH alteration to the bin/ in your home directory as well.
同样,在主目录中注释掉对bin/的任何PATH更改。

If you don't need it, comment-out the section with Conda stuff as well.
如果不需要,同样注释掉包含Conda内容的部分。

Install Jupyter from your package manager. E.g.
从包管理器中安装Jupyter。例如:

sudo apt install python3-notebook

Start a new terminal, and test:
打开一个新的终端并进行测试:

which python
which jupyter

These should point to /usr/bin
这些应该指向/usr/bin

Start your notebook:
启动你的笔记本:

jupyter notebook
英文:

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

huangapple
  • 本文由 发表于 2023年7月18日 16:11:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定