'ImportError: No Module Named 'pysqlite2'

I have written a program in Python which was done on windows. And in the windows test environment worked fine. Now I am setting up a linux server to internally host the program. I have installed all the dependencies etc from a generated requirements file but when I run it I come on a problem,

ImportError: No Module Named 'pysqlite2'.

I have extensively googled this issue and have not found a solution. Can anyone tell me how to fix this problem from code below? I cannot upload an image due to reputation isnt high enough. Any help would be greatly appreciated. If any other information is needed just comment and I will upload.

File "/home/ryan/python_p/venv/lib/python3.4/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 334, in dbapi
    from pysqlite2 import dbapi2 as sqlite
ImportError: No Module named 'pysqlite2'

As far as I understand it sqlite either is not compatible or has compatibility issues?

Another issue that I think is directly related is when inside the virtual environment and I try pip3.4 install pysqlite i get

SyntaxError: Missing Parenthesis in call to 'Print

Its suggests install Sphinx which I did but did not cure.

I think these two issues are directly related and by curing ine should be able to cure the other.



Solution 1:[1]

You could probably just use sqlite3 which is now part of the standard library and should work exactly the same as pysqlite2 does. You can try to modify the file mentioned from:

from pysqlite2 import dbapi2 as sqlite

to

from sqlite3 import dbapi2 as sqlite

Solution 2:[2]

Try pip search sqlite, you may find many candidates. Pick something like this one:

 pip install pysqlite

Solution 3:[3]

For people on CentOS 6 and Python 2.6:

Executing pip install pysqlite directly would result in a gcc error, you would have to yum install sqlite-devel first, before installing pysqlite.

After that, ImportError may still persist, if you are using a Python version different from the Python 2.6 that's shipped with CentOS 6. The error message I got is like:

ImportError: /usr/local/lib/python2.7/site-packages/pysqlite2/_sqlite.so: undefined symbol: sqlite3_stmt_readonly

This is a linking issue, copying below compiled library files from old Py2.6 directory to Py2.7 solved my problem, as inspired by this Github discussion.

cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/

Solution 4:[4]

I faced this issue with multiple python dependent package while setup, specifically while installing jupyter notebook in python virtual enironment in Ubuntu.It is because of sqlite binding for our python.

Error I got:

    from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'

I resolved it by --enable-loadable-sqlite-extensions=yes 1.) First find your python or python version you used for creating virtual env. I have used python3.8 e.g

$ whereis python
python: /usr/bin/python3.6m /usr/bin/python /usr/bin/python3.8 /usr/bin/python2.7-config /usr/bin/python3.8-config  python

$ cd /usr/bin

$ls
python3.8
python3.8-config

Note: there will be many package check for pytho. you will find configure file for each python version, now use specific python version

ox:/usr/bin$ ./python3.8-config --enable-loadable-sqlite-extensions=yes

OR

ox:/usr/bin$ ./python3.8-config --enable-optimizations --enable-loadable-sqlite-extensions

Now, create your virtual env using that python version e.g Go the folder where you want to create the virtual env

$ python3.8 -m venv mlwen_jup_env
$ source mlwen_jup_env/bin/activate

Its done, now you can install packages

Solution 5:[5]

You can do the below changes to make your jupyter notebook work

Replace the file “C:\Windows\System32\sqlite3.dll” by “C:\Users\username\anaconda3\Library\bin\sqlite3.dll”

This will make jupyter notebook work

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stefan
Solution 2 navins
Solution 3 rustberry
Solution 4 Vinay Kumar
Solution 5 Nishanth