189

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:

pip install sqlite

but an error pops up.

2
  • 5
    If your python is built from source manually , and meet this error, you should install sqlite-devel package first, then rebuild python, as @falsetru said, the package name will be vary depending on the Operating system. Commented Mar 28, 2016 at 1:54
  • For everone trying to build python from source and running into this error: This really good answer adresses the bulild process and the dependencys you need. stackoverflow.com/a/6171511/6273503 Commented Sep 28, 2017 at 8:35

8 Answers 8

361

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

Sign up to request clarification or add additional context in comments.

8 Comments

I actually have a python 2.5.4 that does not included sqlite3 :(
@user722915, According to What's New in Python 2.5, The pysqlite module (pysqlite.org), a wrapper for the SQLite embedded database, has been added to the standard library under the package name sqlite3.
if your python3 is built from source manually , and meet this error, you should install sqlite-devel package first, then rebuild python3.
@ngn999, BTW, the package name will be vary depending on the Operating system. For example, in Ubuntu, it's libsqlite3-dev.
LITERALLY LIFED MY SAVE!
|
82

For Python version 3:

pip install pysqlite3 

2 Comments

pysqlite3 is just a wrapper. It won't work if you don't actually have the SQLite libraries in your system (or the devel package if you built Python from sources).
I tried this and it installed, but I still couldn't use it. Any ideas? Here's what it says when I run the command: Preparing metadata (setup.py) ... done Using legacy 'setup.py install' for pysqlite3, since package 'wheel' is not installed. Installing collected packages: pysqlite3 Running setup.py install for pysqlite3 ... done Successfully installed pysqlite3
43

I have python 2.7.3 and this solved my problem:

pip install pysqlite

1 Comment

Consider that this is not applicable to Python 3.
29

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

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

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 managed package installation. This would give you an independent development environment. In this case, the solution is to install sqlite3 modularly too.

2 Comments

Can also happen if you use pyenv to manage your Python versions, but you didn't have all the system packages installed when the Python interpreter was installed.
I had a requirement where I didn't want to disturb the existing python setup. This is exactly what I needed. Thanks !!
7

if you have error in Sqlite built in python you can use Conda to solve this conflict

conda install sqlite

Comments

2

For Jupyter Notebook and pyenv users I found this: https://github.com/jupyterlab/jupyterlab/issues/4181

So basically sqlite3 did not come with python 3.6 or something of that sort

You need to:

  1. Install libsqlite3-dev
sudo apt install libsqlite3-dev
  1. Reinstall python 3.6 with pyenv
pyenv install 3.6

Comments

0

For Windows + Conda users: you have to download the sqlite3 dll, uncompress and copy the file into the DLL dir in Conda installion path

Check this answer for more detail

Comments

-3

sqlite3 automatically comes with python. You can upgrade python version if you need latest version of sqlite3 or follow steps from https://www.sqlite.org/download.html

1 Comment

It depends very much how you install python and on which platform if sqlite3 if included

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.