Cannot import sqlite3 in Python3
<p>I am unable to import the sqlite3 module in Python, version 3.5.0. Here's what I get:</p>

<p><code>&gt;&gt;&gt; import sqlite3
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in &lt;module&gt;
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in &lt;module&gt;
    from _sqlite3 import *
ImportError: No module named '_sqlite3'</code></p>

<p>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:</p>

<ol>
<li><p>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.</p></li>
<li><p><a href="http://stackoverflow.com/questions/1210664/no-module-named-sqlite3">This helpful question</a> looked promising. I tried to re-configure and re-compile Python3.5 with the <code>--enable-loadable-sqlite-extensions</code> option, as user jammyWolf suggested. Nope, same error still occurs.</p></li>
<li><p>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.</p></li>
<li><p>I noticed that in the error message, it says <code>No module named '_sqlite3'</code>. <a href="http://stackoverflow.com/questions/20757763/why-are-modules-imported-as-name-in-another-module">This thread</a> 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.</p></li>
</ol>

<p>Any ideas?</p>

<p>Install <a href="http://centos-packages.com/7/package/sqlite-devel/" rel="nofollow"><code>sqlite-devel</code></a> package which includes header, library that is required to build <code>sqlite3</code> extension.</p>

<pre><code>yum install sqlite-devel
</code></pre>

<p><strong>NOTE</strong>: Python does not include <code>sqlite3</code> library itself, but an extension module (wrapper).</p>

python linux python-3.x sqlite3 python-import