lin*_*ion 3 centos python software-installation sqlite python3
我已经在 Centos 7.4 机器上安装了 Python 3.6,并且需要 SQLite 的更新版本(我正在使用一些新功能)。它附带的 SQLite 版本非常旧:3.7.17。
这是怎么做到的?在 Windows 上,将 Python\DLLs 目录中的 sqlite.dll 文件替换为所需的文件很简单,但我没有找到如何在 Linux 上执行此操作的信息。
我可以看到这个问题之前有人问过,但没有回答 - /sf/ask/2734513071/ - 这是我唯一的页面谷歌搜索;大多数其他结果是 Python 2/pysqlite,这对我没有帮助。
那么,如何在 CentOS 机器上更新 Python 使用的 SQLite 版本呢?
您需要找到具有较新版本的 RPM,或者需要下载适用于您的操作系统的预编译二进制文件 ( https://www.sqlite.org/download.html ) 或下载源代码/编译/安装软件。
通常建议保留 RPM,以便更好地管理软件(用于安装、升级等),但如果您找不到可用的 RPM,请随意尝试安装预编译版本或编译软件并安装它。这通常在 Linux 系统上完成,以获得运行某些软件所需的最新或特定版本的软件。
编译 SQLite 后,您应该能够指向 python 的库,一种快速方法是将 LD_LIBRARY_PATH 设置为从 SQLite 编译中获得的 lib 目录的输出:
Libraries have been installed in:
/usr/local/sqlite-3.22.0/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
如果您在设置库之前运行 python,您将看到旧版本:
python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.7.17
Run Code Online (Sandbox Code Playgroud)
使用新版本:
export LD_LIBRARY_PATH=/usr/local/sqlite-3.22.0/lib
python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.22.0
Run Code Online (Sandbox Code Playgroud)
根据您的环境,您可能需要在代码中或在代码运行之前进行设置,具体取决于您管理不同版本的库的方式。尽管编译的输出可以给你一些关于这方面的想法。
| 归档时间: |
|
| 查看次数: |
13805 次 |
| 最近记录: |