Cannot import sqlite3 in Python3
Falsetru is correct, I am going to go into a bit more detail for those not familiar (linux instructions). If you are getting this error, chances are you are using a version of python that was compiled without the correct headers. Here's a step by step guide to get it sorted. (Python 3.X.X instructions)
- Install the required sqlite libraries
sudo apt-get install libsqlite3-dev
- Uninstall python (I'm using python 3.6.5 as an example in this guide)
sudo apt-get remove python3.6
- Download python from source
cd /tmp && wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
- Unpack the archive
tar -xvf Python-3.6.5.tgz
- Configure
cd Python-3.6.5 && ./configure
- Make and install (and go make coffee while you're at it)
make && sudo make install
If you did everything correctly running "python3.6 -V" should give you your python version. Note you will have to rebuild any virtual environments you have as well.
One final caveat you may encounter.
zipimport.ZipImportError: can't decompress data; zlib not available
This happens if you don't have the following zlib library installed:
sudo apt-get install zlib1g-dev
Install sqlite-devel
package which includes header, library that is required to build sqlite3
extension.
yum install sqlite-devel
NOTE: Python does not include sqlite3
library itself, but an extension module (wrapper).
I copied sqlite3.dll to this folder:
C:\Users\*****\Anaconda3\DLLs
It worked after two weeks trying everything else.