python3.5看到但python3.9看不到sqlite3 [英] python3.5 sees but python3.9 does not see sqlite3

查看:240
本文介绍了python3.5看到但python3.9看不到sqlite3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器:Linux eyes 4.9.0-9-amd64#1 SMP Debian 4.9.168-1 + deb9u3(2019-06-16)x86_64 GNU/Linux

即python3.5是其本机python3

系统中有两个python3:
root @ machine:#update-alternatives --list python3
/usr/bin/python3.5
/usr/local/bin/python3.9

  root @ machine:#update-alternatives --config python3替代python3有2个选择(提供/usr/bin/python3).选择路径优先状态---------------------------------------------------------------0/usr/local/bin/python3.9 2 自动模式1/usr/bin/python3.5 1手动模式* 2/usr/local/bin/python3.9 2手动模式+++++++++++首先让我们选择+++++++++++root @ machine:#python3Python 3.5.3(默认,2020年11月18日,21:09:16)Linux上的[GCC 6.3.0 20170516]键入帮助",版权",信用".或许可证"想要查询更多的信息.>>>导入sqlite3< ------------确定>>>出口()** +++++++++++现在就让我们选择2 +++++++++++++root @ machine:#python3Python 3.9.0(默认,2020年11月23日,09:50:01)Linux上的[GCC 6.3.0 20170516]键入帮助",版权",信用".或许可证"想要查询更多的信息.>>>导入sqlite3追溯(最近一次通话):在< module>中的文件< stdin>"第1行.< module>中的文件"/usr/local/lib/python3.9/sqlite3/__init__.py",第23行.从sqlite3.dbapi2导入*< module>中的文件"/usr/local/lib/python3.9/sqlite3/dbapi2.py",第27行.从_sqlite3导入*ModuleNotFoundError:没有名为"_sqlite3"的模块< -------什么?>>>出口()++++++++++++++++++++++++++++++++++++++++++++++root @ machine:#头〜/python3-9_distr/Python-3.9.0/config.log该文件包含编译器生成的所有消息,而运行configure,以帮助在configure出错时进行调试.它是由python configure 3.9创建的,由GNU Autoconf 2.69生成.调用命令行为$ ./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根96552 Nov 18 23:09 _sqlite3.cpython-35m-x86_64-linux-gnu.so但是/usr/local/lib/python3.9/lib-dynload DID没有_sqlite3.*我复制了_sqlite3.cpython-35m-x86_64-linux-gnu.so并重命名为-rwxr-xr-x 1根root 96552 Nov 18 23:09 _sqlite3.cpython-3 ** 9 ** m-x86_64-linux-gnu.so一切都没有改变. 

++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++
怎么来的 ?如何在我的python3.9中使sqlite3工作?

更新:

我找到了解决方案".如前所述,我复制了
/var/lib/python3.5/lib-dynload/
_sqlite3.cpython-35m-x86_64-linux-gnu.so

并重命名为
/var/local/lib/python3.9/lib-dynload/
_sqlite3.cpython-3 9 m-x86_64-linux-gnu.so

但它没有用.
然后我复制了
_sqlite3.cpython-3 9 m-x86_64-linux-gnu.so

同一文件夹(/var/local/lib/python3.9/lib-dynload/)中的 _sqlite3.so
它似乎正在工作,但后来我收到了新问题.

解决方案

在安装 python3.9 之后,您是否检查了python使用的 PATH 变量?/p>

请转到终端并输入

 <代码>〜$ python3.6 

Linux上的

  [GCC 9.3.0]键入帮助",版权",信用".或许可证"想要查询更多的信息.>>>导入系统>>>系统路径 

您应该得到类似这样的东西

['','/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"]

注意我使用的是python3.8,因此输出将有所不同

对python3.9做同样的事情,并检查您尝试访问的软件包是否已安装在这些路径中.

如果您想进一步了解如何添加到路径,请参考此问题 Linux上的PYTHONPATH

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.

解决方案

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

这篇关于python3.5看到但python3.9看不到sqlite3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆