I am trying to use Spyder 6 IDE on Ubuntu 24.04. After installation of Spyder 6, I changed the default python interpreter to my virtual environment running Python 3.11 and installed spyder-kernels==3.0 in order to have the python console within the IDE. However, instead of the python console showing up, I get the following error:
Traceback (most recent call last):
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/console/__main__.py", line 24, in
start.main()
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/console/start.py", line 151, in main
import_spydercustomize()
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/console/start.py", line 41, in import_spydercustomize
import spydercustomize # noqa
^^^^^^^^^^^^^^^^^^^^^^
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/customize/spydercustomize.py", line 19, in
from spyder_kernels.customize.spyderpdb import SpyderPdb
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/customize/spyderpdb.py", line 22, in
from IPython.core.autocall import ZMQExitAutocall
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/IPython/__init__.py", line 55, in
from .terminal.embed import embed
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/IPython/terminal/embed.py", line 15, in
from IPython.core.interactiveshell import DummyMod, InteractiveShell
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/IPython/core/interactiveshell.py", line 110, in
from IPython.core.history import HistoryManager
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/IPython/core/history.py", line 10, in
import sqlite3
File "/home/katmatzidis/.pyenv/versions/3.11.10/lib/python3.11/sqlite3/__init__.py", line 57, in
from sqlite3.dbapi2 import *
File "/home/katmatzidis/.pyenv/versions/3.11.10/lib/python3.11/sqlite3/dbapi2.py", line 27, in
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
Traceback (most recent call last):
File "/home/katmatzidis/.pyenv/versions/3.11.10/lib/python3.11/runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/katmatzidis/.pyenv/versions/3.11.10/lib/python3.11/runpy.py", line 88, in _run_code
exec(code, run_globals)
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/console/__main__.py", line 24, in
start.main()
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/console/start.py", line 151, in main
import_spydercustomize()
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/console/start.py", line 41, in import_spydercustomize
import spydercustomize # noqa
^^^^^^^^^^^^^^^^^^^^^^
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/customize/spydercustomize.py", line 19, in
from spyder_kernels.customize.spyderpdb import SpyderPdb
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/spyder_kernels/customize/spyderpdb.py", line 22, in
from IPython.core.autocall import ZMQExitAutocall
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/IPython/__init__.py", line 55, in
from .terminal.embed import embed
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/IPython/terminal/embed.py", line 15, in
from IPython.core.interactiveshell import DummyMod, InteractiveShell
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/IPython/core/interactiveshell.py", line 110, in
from IPython.core.history import HistoryManager
File "/home/katmatzidis/.virtualenvs/r‑tensorflow/lib/python3.11/site‑packages/IPython/core/history.py", line 10, in
import sqlite3
File "/home/katmatzidis/.pyenv/versions/3.11.10/lib/python3.11/sqlite3/__init__.py", line 57, in
from sqlite3.dbapi2 import *
File "/home/katmatzidis/.pyenv/versions/3.11.10/lib/python3.11/sqlite3/dbapi2.py", line 27, in
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
What is this sqlite3 package? It seems I don’t have it in my python virtual environment. How do I install it?
I tried to install the sqlite3 package by running the following command from Ubuntu terminal:
~$ .virtualenvs/r-tensorflow/bin/pip install sqlite3
However, pip is unable to find such a package. I also tried other variants after researching the problem online such as
$ .virtualenvs/r-tensorflow/bin/pip install libsqlite3-dev
but the same problem persists. What am I doing wrong? The default python version that comes with Spyder 6 (the internal python) runs fine in the IPython console, but my virtual environment python has the above error.
I actually found that sqlite3 is in the site-packages of my python virtual environment buried in
Ubuntuhomekatmatzidis.virtualenvsr-tensorflowlibpython3.11site-packagesjedithird_partydjango-stubsdjango-stubsdbbackendssqlite3
Now I’m definitely not sure why it’s not working. I appreciate the help!
2
Answers
It turns out I was missing a file called
_sqlite3.cpython-311-x86_64-linux-gnu.so
from the lib-dynload library located at /home/katmatzidis/.pyenv/versions/3.11.10/lib/python3.11/lib-dynload. This is what the error means byModuleNotFoundError: No module named '_sqlite3'.
I found a copy of the file from the Spyder6 internal python files at /home/katmatzidis/spyder-6/envs/spyder-runtime/lib/python3.11/lib-dynload and copied it to my lib-dynload library and the IPython console worked.What you did was not a solution, but a hack.
First, the sqlite3 module is part of the Python standard library since Python 2.5. There is no need to install it using pip or anything similar.
On Ubuntu 24.04, the default Python version is 3.12, where the sqlite3 module is working by default.
Now you have created a Pyhton 3.11 virtual environment. This functionality depends on "pyenv" which is a Python environment manager to install arbitrary Python versions. If you use pyenv then certain OS dependencies need to be installed for full functionality.
In the Ubuntu case, installing the "libsqlite3-dev" package should make sure that the sqlite3 module can always be built from source. While you are at it, make sure that you also have instealled the "build-essential" package. This should do it:
You will then need to reinstall your pyenv for Python 3.11 and recreate the virtualenv.