1
votes

My machine: Linux eyes 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1+deb9u3 (2019-06-16) x86_64 GNU/Linux

i.e. python3.5 is its native python3

Have two python3 in the system:
root@machine: # update-alternatives --list python3
/usr/bin/python3.5
/usr/local/bin/python3.9

root@machine: # update-alternatives --config python3  
There are 2 choices for the alternative python3 (providing
/usr/bin/python3).  
Selection    Path                      Priority  Status  
---------------------------------------------------------------
  0            /usr/local/bin/python3.9   2         auto mode  
  1            /usr/bin/python3.5         1         manual mode  
* 2            /usr/local/bin/python3.9   2         manual mode


+++++++++++ LET'S CHOOSE 1 FIRST +++++++++++  
root@machine: # python3  
Python 3.5.3 (default, Nov 18 2020, 21:09:16)  
[GCC 6.3.0 20170516] on linux  
Type "help", "copyright", "credits" or "license" for more information.  
>>> import sqlite3             <------------ OK  
>>> exit() 


**+++++++++++ LET'S CHOOSE 2 NOW +++++++++++++  
root@machine: # python3  
Python 3.9.0 (default, Nov 23 2020, 09:50:01)  
[GCC 6.3.0 20170516] on linux  
Type "help", "copyright", "credits" or "license" for more information.  
>>> import sqlite3 
Traceback (most recent call last):  
  File "<stdin>", line 1, in <module>  
  File "/usr/local/lib/python3.9/sqlite3/__init__.py", line 23, in <module>  
    from sqlite3.dbapi2 import *  
  File "/usr/local/lib/python3.9/sqlite3/dbapi2.py", line 27, in <module>  
    from _sqlite3 import *  
ModuleNotFoundError: No module named '_sqlite3'   <------- WHAT?  
>>> exit()  


++++++++++++++++++++++++++++++++++++++++++++  
root@machine: # head ~/python3-9_distr/Python-3.9.0/config.log  
This file contains any messages produced by compilers while  
running configure, to aid debugging if configure makes a mistake.  

It was created by python configure 3.9, which was  
generated by GNU Autoconf 2.69.  Invocation command line was  

  $ ./configure --enable-optimizations --enable-loadable-sqlite-extensions  

++++++++++++++++++++++++++++++++++++++++++++  
/usr/lib/python3.5/lib-dynload# ls -la _sqlite3.cpython-35m-x86_64-linux-gnu.so  
-rw-r--r-- 1 root root 96552 Nov 18 23:09 _sqlite3.cpython-35m-x86_64-linux-gnu.so  

BUT /usr/local/lib/python3.9/lib-dynload   DID NOT HAVE _sqlite3.*  

I copied _sqlite3.cpython-35m-x86_64-linux-gnu.so and renamed to  
-rwxr-xr-x 1 root root 96552 Nov 18 23:09 _sqlite3.cpython-3**9**m-x86_64-linux-gnu.so  


Nothing had changed.  

++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++
How come ? How can I make sqlite3 work in my python3.9 ?

UPDATE:

I have found a "solution". As I mentioned before, I copied
/var/lib/python3.5/lib-dynload/
_sqlite3.cpython-35m-x86_64-linux-gnu.so

and renamed to
/var/local/lib/python3.9/lib-dynload/
_sqlite3.cpython-39m-x86_64-linux-gnu.so

but it did not work.
Then I copied
_sqlite3.cpython-39m-x86_64-linux-gnu.so
to
_sqlite3.so in the same folder (/var/local/lib/python3.9/lib-dynload/)
It seemed to be working but later I got new problem.

1
Why are you shouting so loud? Well it seems to be your first post, but it looks like you tried to use all the possible formats in the same question. As a result it is hard to read, which is not what you want... For your question, this is a known problem in clever OS like Linux distribs. Package maintainers know that most users will only use a subset of Python so they have breaked the standard installation in a number of packages. If you can start python3.9 but cannot find the sqlite3 module, you have to find in which debian package it is contained and install it.Serge Ballesta
Dear Serge Ballesta, thank you for your reprimand. I wanted not to use so many formatting but stackoverflow forced me. "Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon." There are only four line of code (import and exit()) but it sees more. I tried to remove unnecessary formating after your words but I spent a lot of time trying it. Finally I had to leave it as is.C4H7Cl2O4P
# apt install libsqlite3-dev libsqlite3-dev is already the newest version (3.16.2-5+deb9u2). # apt install sqlite3 The following NEW packages will be installed: sqlite3 The following packages will be upgraded: libsqlite3-0 libsqlite3-dev Nothing had changed. Anyway thank you very much, I do appreciate your help.C4H7Cl2O4P
Beware, I am not a Debian user, but on my distrib there are python-x.y-sqlite-z.t packages. Just installing the last version of sqlite3-dev has no direct impact of making Python able to use it.Serge Ballesta

1 Answers

0
votes

Hi after you have installed python3.9 have you checked the PATH variable which python uses?

please go to a terminal and type

~$ python3.6
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path

You should get something that looks like this

['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/jishnu/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']

Note i'm using python3.8 hence output will be different

Do the same thing for your python3.9 and check if the package you are trying to access is installed in any of these paths.

If you want further help on how to add to path, refer this question PYTHONPATH on Linux