问题
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:
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
来源:https://stackoverflow.com/questions/65336876/python3-5-sees-but-python3-9-does-not-see-sqlite3