如何将 sqlite3 模块添加到 Python?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19530974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:59:24  来源:igfitidea点击:

How can I add the sqlite3 module to Python?

pythonsqlitepip

提问by Jin-Dominique

Can someone tell me how to install the sqlite3 module alongside the most recent version of Python? I am using a Macbook, and on the command line, I tried:

有人能告诉我如何在最新版本的 Python 旁边安装 sqlite3 模块吗?我正在使用 Macbook,并在命令行上尝试:

pip install sqlite

but an error pops up.

但是会弹出一个错误。

采纳答案by falsetru

You don't need to install sqlite3module. It is included in the standard library (since Python 2.5).

您不需要安装sqlite3模块。它包含在标准库中(自 Python 2.5 起)。

回答by nicolimo86

I have python 2.7.3 and this solved my problem:

我有 python 2.7.3,这解决了我的问题:

pip install pysqlite

回答by Jonathan Komar

Normally, it is included. However, as @ngn999 said, if your python has been built from source manually, you'll have to add it.

通常,它包括在内。但是,正如@ngn999 所说,如果您的python 是手动从源代码构建的,则必须添加它。

Here is an example of a script that will setup an encapsulated version (virtual environment) of Python3in your user directory with an encapsulated version of sqlite3.

下面是一个脚本示例,该脚本将在您的用户目录中使用sqlite3封装版本设置Python3封装版本(虚拟环境)

INSTALL_BASE_PATH="$HOME/local"
cd ~
mkdir build
cd build
[ -f Python-3.6.2.tgz ] || wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
tar -zxvf Python-3.6.2.tgz

[ -f sqlite-autoconf-3240000.tar.gz ] || wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
tar -zxvf sqlite-autoconf-3240000.tar.gz

cd sqlite-autoconf-3240000
./configure --prefix=${INSTALL_BASE_PATH}
make
make install

cd ../Python-3.6.2
LD_RUN_PATH=${INSTALL_BASE_PATH}/lib configure
LDFLAGS="-L ${INSTALL_BASE_PATH}/lib"
CPPFLAGS="-I ${INSTALL_BASE_PATH}/include"
LD_RUN_PATH=${INSTALL_BASE_PATH}/lib make
./configure --prefix=${INSTALL_BASE_PATH}
make
make install

cd ~
LINE_TO_ADD="export PATH=${INSTALL_BASE_PATH}/bin:$PATH"
if grep -q -v "${LINE_TO_ADD}" $HOME/.bash_profile; then echo "${LINE_TO_ADD}" >> $HOME/.bash_profile; fi
source $HOME/.bash_profile

Why do this? You might want a modular python environment that you can completely destroy and rebuild without affecting your operating system–for an independent development environment. In this case, the solution is to install sqlite3 modularly too.

为什么要这样做?您可能需要一个模块化的 Python 环境,您可以在不影响操作系统的情况下完全销毁和重建它——用于独立的开发环境。在这种情况下,解决方案也是模块化安装 sqlite3。

回答by Hoss

For Python version 3:

对于 Python 版本 3:

pip install pysqlite3