SQLITE3 cannot be imported in Python 3

sqlite works fine with python 2.7, but when I try to import it in python 3, it will give an error

 > Traceback (most recent call last): File "dbConnection.py", line 1,
> in
> import sqlite3 File "/usr/local/lib/python3.4/sqlite3/ __init__.py", line 23, in
> from sqlite3.dbapi2 import * File "/usr/local/lib/python3.4/sqlite3/dbapi2.py", line 27, in
> from _sqlite3 import * ImportError: No module named'_sqlite3'

Remove this error I tried to reinstall sqlite3

sudo apt-get install sqlite3

but it says that the package already exists. I tried to install it afterwards

pip3 install sqlite3

but it will Error

Collecting sqlite3
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by'ProxyError(' Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/
Retrying (Retry(total=3, connect=None, read=None, redirect =None)) after connect ion broken by'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/
Retrying (Retry(total=2, connect= None, read=None, redirect=None)) after connection broken by'ConnectTimeoutError(,'Connection to 196.1.114.80 timed out. (connect timeout= 15)')': /simple/sqlite3/
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by'ProxyError('Cannot connect to proxy.' , error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/
Could not find a version that satisfies the requirement sqlite3 ( from versions: )
N o matching distribution found for sqlite3

But my connection is good…
What should I do now to import sqlite3 in python 3?

sqlite3 is an optional part of the standard library. It is compiled when Python 3 is compiled and installed , But only if the correct sqlite3 include files (development header files) are available.

If you have compiled and installed Python 3 yourself, please install the dependencies (e.g. libsqlite3-dev or sqlite-devel or Similar, depending on your Linux distribution), then recompile and reinstall Python 3.

Externally, the library remains as pysqlite; but that release doesn’t support Python 3. Even so, to install it, you still need those sqlite development files, you need to port it to Python 3. You can also recompile Python 3.

sqlite works fine with python 2.7, but when I try to import it in python 3, it will error

> Traceback (most recent call last): File "dbConnection.py", line 1,
> in
> import sqlite3 File "/usr/local/lib/python3.4/sqlite3/__init__.py", line 23, in < module>
> from sqlite3.dbapi2 import * File "/usr/local/lib/python3.4/sqlite3/dbapi2.py", line 27, in
> from _sqlite3 import * ImportError : No module named'_sqlite3'

Removing this error I tried to reinstall sqlite3

sudo apt-get install sqlite3

but It said that the package already exists. Afterwards I tried to install it

pip3 install sqlite3

But there will be an error when installing again

Collecting sqlite3
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/
Retrying (Retry(total=3, connect =None, read=None, redirect=None)) after connection broken by'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/< br /> Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by'ConnectTimeoutError(, 'Connection to 196.1.114.80 timed out. (connect timeout=15)')': /simple/sqlite3/
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 407 Proxy Authen tication Required',))': /simple/sqlite3/
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by'ProxyError('Cannot connect to proxy .', error('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/sqlite3/
Could not find a version that satisfies the requirement sqlite3 (from versions: )
No matching distribution found for sqlite3

But my connection is good…
What should I do now to import sqlite3 in python 3?

sqlite3 is an optional part of the standard library. It is compiled when Python 3 is compiled and installed, but only if the correct sqlite3 include file (development header File) is available.

If you have compiled and installed Python 3 yourself, install the dependencies (e.g. libsqlite3-dev or sqlite-devel or similar, depending on your Linux distribution) , Then recompile and reinstall Python 3.

Externally, the library remains as pysqlite; but that release doesn’t support Python 3. Even so, to install it, you Those sqlite development files are still needed, you need to port it to Python 3. You can also recompile Python 3.

Leave a Comment

Your email address will not be published.