当前位置:Gxlcms > 数据库问题 > python安装sqlite3模块

python安装sqlite3模块

时间:2021-07-01 10:21:17 帮助过:157人阅读

于是打开Python 测试下能否导入sqlite3模块

>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/usr/local/lib/python2.7/sqlite3/dbapi2.py", line 28, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

结果是没有,我原来以为Python自带的呢,

用pip install sqlite3 结果安装不了!如下:

Collecting sqlite3
  Using cached sqlite3-99.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-Tpr4M6/sqlite3/setup.py", line 2, in <module>
        raise RuntimeError("Package ‘sqlite3‘ must not be downloaded from pypi")
    RuntimeError: Package ‘sqlite3‘ must not be downloaded from pypi
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-Tpr4M6/sqlite3/

网上参考了两个博客

http://www.pythonclub.org/python-files/sqlite 和

http://www.python88.com/topic/420/

下载与安装SQLITE3

下载 sqlite-autoconf-3190300.tar.gz

在 https://sqlite.org/download.html 这里下载。我下载的是

安装方法是:

  1. 解压
  2. ./configure --prefix=/usr/local/lib/python2.7/dist-packages/sqlite3   #目录下面要用的
  3. make
  4. make install
  5. 安装完测试一下,看是否能导入sqlite3模块,我还是不行

那就重新安装python吧

不管有没有安装过Python,这里都必须重新进行安装,安装前,需要更改源码目录下的setup.py

可以查找sqlite关键字,找到如下行,在末尾加上sqlite的安装路径

sqlite_incdir = sqlite_libdir = None
        sqlite_inc_paths = [ ‘/usr/include‘,
                             ‘/usr/include/sqlite‘,
                             ‘/usr/include/sqlite3‘,
                             ‘/usr/local/include‘,
                             ‘/usr/local/include/sqlite‘,
                             ‘/usr/local/include/sqlite3‘,
                             ‘/usr/local/lib/python2.7/dist-packages/sqlite3‘,
                           ]

安装完后,再测试一下,看是否成功

1. 方法一:先看下Lib是否已经生成

还是在 /home/user/usr/python/python2.7/lib/python2.7/lib-dynload 下

发现了 _sqlite3.so 文件

2. 方法二:使用python 命令

>>> import sqlite3
不报错即可!

python安装sqlite3模块

标签:string   __init__   tput   error:   make   dir   complete   htm   call   

人气教程排行