I am unable to import the sqlite3 module in Python, version 3.5.0. Here's what I get:
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
I know, I know, there are PLENTY of StackOverflow posts and support forums across the web where people complain about this problem, but none of the posted solutions have worked for me so far. Here's where I've been:
I also have Python 2.6.6 installed on this server, which is running CentOS 6.8 x86_64. I can open up the Python REPL and import sqlite3 just fine when using Python 2.6.6. I can also use sqlite3 from straight from bash and nothing seems awry.
This helpful question looked promising. I tried to re-configure and re-compile Python3.5 with the --enable-loadable-sqlite-extensions
option, as user jammyWolf suggested. Nope, same error still occurs.
I've been using virtual environments like a good boy, but I have root access to this server. So, I was a bad boy and ran python3 as root without any virtualenvs activated. Still no luck. So I don't think it has anything to do with permissions.
I noticed that in the error message, it says No module named '_sqlite3'
. This thread suggests that the underscore before the module name means that the module is an implementation detail, and isn't exposed in the API. ... I'm not sure what to make of this information, but there may be a hint somewhere in there.
Any ideas?
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)
sudo apt-get install libsqlite3-dev
sudo apt-get remove python3.6
cd /tmp && wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar -xvf Python-3.6.5.tgz
cd Python-3.6.5 && ./configure
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With