I'll try to be as clear and specific as possible because I've seen so many people with the same problem, but none of the answers they had worked for me.
The problem in question is: missing modules when trying to import other modules, that (by far as I understand) are installed by default in Python 3.11. eg: missing _sqlite3 when importing sqlite3.
Python 3.11.0 (main, Jan 12 2023, 03:19:52) [GCC 9.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import sqlite3Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/user_name/opt/Python-3.11.0/lib/python3.11/sqlite3/__init__.py", line 57, in <module> from sqlite3.dbapi2 import * File "/home/user_name/opt/Python-3.11.0/lib/python3.11/sqlite3/dbapi2.py", line 27, in <module> from _sqlite3 import *ModuleNotFoundError: No module named '_sqlite3'
Context
I'm currently working on a Dreamhost VPS, running on Ubuntu 20.04.5. Since it's a Dreamhost VPS keep in mind I can't uso sudo.
I've Python 3.8 installed globally, but I'm trying to set Python 3.11 with venv. The steps to install Python 3.11 were, as indicated by 'Installing a custom version of Python 3 by Dreamhost':
- cd /home/user_name/opt
- wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz
- tar zxvf Python-3.11.0.tgz
- cd Python-3.11.0
- ./configure --prefix=$HOME/opt/Python-3.11.0
- make
- make install
When running the make command I saw the following message:
The necessary bits to build these optional modules were not found:_bz2 _curses _curses_panel_lzma _tkinter _uuidreadlineTo find the necessary bits, look in setup.py in detect_modules() for the module's name.The following modules found by detect_modules() in setup.py have notbeen built, they are *disabled* by configure:_sqlite3
This is my detect_modules() in setup.py:
def detect_modules(self): # remove dummy extension self.extensions = [] # Some C extensions are built by entries in Modules/Setup.bootstrap. # These are extensions are required to bootstrap the interpreter or # build process. self.detect_simple_extensions() self.detect_test_extensions() self.detect_readline_curses() self.detect_crypt() self.detect_openssl_hashlib() self.detect_hash_builtins() self.detect_dbm_gdbm() self.detect_sqlite() self.detect_platform_specific_exts() self.detect_nis() self.detect_compress_exts() self.detect_expat_elementtree() self.detect_multibytecodecs() self.detect_decimal() self.detect_ctypes() self.detect_multiprocessing() self.detect_tkinter() self.detect_uuid() # Uncomment the next line if you want to play with xxmodule.c# self.add(Extension('xx', ['xxmodule.c'])) self.addext(Extension('xxlimited', ['xxlimited.c'])) self.addext(Extension('xxlimited_35', ['xxlimited_35.c']))
So after running the commands I just mentioned, I proceeded to setup the virtualenv to test Python 3.11:
- cd /home/user_name/opt
- /home/user_name/opt/Python-3.11.0/bin/python3 -m venv venv
- source venv/bin/activate
And then I got the ModuleNotFoundError I mentioned at the start of the question.
Things I tried/saw:
When I checked my Python 3.11 directory, I saw that in /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload the cpython files for the modules I don't have are just not there, e.g: /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-311-x86_64-linux-gnu.so* where as in my Python 3.8, they're indeed there: /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so
I tried copying the cpython file from my 3.8 to my 3.11 and renaming it:
- cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload
- mv /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /home/user_name/opt/Python-3.11.0/lib/python3.11/lib-dynload/_sqlite3.cpython-311-x86_64-linux-gnu.so
Then when I ran Python 3.11 I got the following error:
Python 3.11.0 (main, Jan 12 2023, 04:33:33) [GCC 9.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import _sqlite3 # this works just fine>>> import sqlite3 # throws error356306 segmentation fault (core dumped) python
Tried recompiling Python and running ./configure --prefix=$HOME/opt/Python-3.11.0 --enable-loadable-sqlite-extensions and didn't work.
Hope I was clear enough and thanks in advance.