如何更新SQLite?

mv1qrgav  于 2022-11-14  发布在  SQLite
关注(0)|答案(3)|浏览(379)

使用本地的Jupyter Notebook、SQLite、Pandas和Ploly,我想将该笔记本移到Colab网站,但它报告的是SQLite版本3.22,而不是3.30。我使用的是自SQLite 3.28以来可用的窗口函数,因此必须升级。我试过:

!apt-get update
!apt-get upgrade sqlite3

这告诉我我使用的是SQLite 3.22。这个问题可能会如何解决?
!apt-cache policy sqlite3结果:

sqlite3:
  Installed: 3.22.0-1ubuntu0.2
  Candidate: 3.22.0-1ubuntu0.2
  Version table:
 *** 3.22.0-1ubuntu0.2 500
        500 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
        100 /var/lib/dpkg/status
     3.22.0-1 500
        500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages
unguejic

unguejic1#

以下是如何升级到最新版本的方法

!curl https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release | tar xz
%cd sqlite/
!./configure
!make sqlite3.c
%cd /content
!npx degit coleifer/pysqlite3 -f
!cp sqlite/sqlite3.[ch] .
!python setup.py build_static build
!cp build/lib.linux-x86_64-3.7/pysqlite3/_sqlite3.cpython-37m-x86_64-linux-gnu.so \
     /usr/lib/python3.7/lib-dynload/
# then MENU: Runtime > Restart runtime ...
import sqlite3
sqlite3.sqlite_version  # 3.36.0

以下是针对Python3.7更新的example notebook
我的GDrive上的一个更快的(预编译)版本。

!gdown 1BSHIKQ7rFw5BpTq5nw1UZfjPK_7Mpnbi -O /usr/lib/python3.7/lib-dynload/
# MENU: Runtime > Restart runtime
import sqlite3
sqlite3.sqlite_version  # '3.38.0'
vbkedwbf

vbkedwbf2#

问题1:安装的Sqlite3太旧。
我们可以利用Google部署最新的Ubuntu LTS代码,如下所示,通过访问Ubuntu存储库。由Canonical资助的Dqlite团队为dqlite维护了一个PPA,该PPA依赖于最新稳定的Sqlite3。我们可以用三行来升级Sqlite3。

!sudo add-apt-repository -y ppa:dqlite/stable
!sudo apt update
!sudo apt-get install -y sqlite3

Codelab环境

!lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:    18.04
Codename:   bionic

https://dqlite.io/docs/faqhttps://launchpad.net/~dqlite/+archive/ubuntu/stable
问题2:Codelab已将sqlite3加载到内存中

!lsof -p `ps -ef | grep ipykernel_launcher | head -n 1 | awk '{print $2}'`  | grep sql
python3 131 root  mem       REG                7,0          2359698 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6 (path dev=0,46)
python3 131 root  mem       REG                7,0          5772741 /usr/lib/python3.6/lib-dynload/_sqlite3.cpython-36m-x86_64-linux-gnu.so (path dev=0,46)

如下所示,libsqlite3被加载到内存中。除非重新启动Python3进程,否则Python3解释器将无法使用新安装的SQlite3
方法一:杀死巨蟒。使运行时内核崩溃,juypter笔记本将重新启动它。

!sudo add-apt-repository -y ppa:dqlite/stable
!sudo apt update
!sudo apt-get install -y sqlite3
!sqlite3 --version
import sqlite3
print(sqlite3.sqlite_version_info)
### 
!kill `ps -ef | grep ipykernel_launcher | head -n 1 | awk '{print $2}'; /usr/bin/python3 -m ipykernel_launcher -f /root/.local/share/jupyter/runtime/kernel-*.json`
###
import sqlite3
sqlite3.sqlite_version_info

方法2:退出内核最佳解决方案

!sudo add-apt-repository -y ppa:dqlite/stable
!sudo apt update
!sudo apt-get install -y sqlite3
!sqlite3 --version
import sqlite3, os
print(sqlite3.sqlite_version_info)
os._exit(00)
import sqlite3
print(sqlite3.sqlite_version_info)

Restart ipython Kernel with a command from a cell

zzwlnbp8

zzwlnbp83#

您可以直接从pysqlite3模块安装SQLite二进制文件。安装和导入所需时间不到5秒。

from time import process_time
start_time = process_time()
import subprocess
try:
    import google.colab # if colab exists, install pysqlite-binary
    subprocess.run(['pip', 'install', 'pysqlite3-binary'], capture_output=False)
    import pysqlite3 as sqlite3

except ModuleNotFoundError:
    pass
end_time = process_time()

print(f'Time to install (sec): {round(end_time-start_time, 3)}')
print(f'SQLite version: {sqlite3.sqlite_version}')

相关问题