13

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.

Tim
  • 41,901
  • 18
  • 127
  • 145
Ryan McKinney
  • 183
  • 1
  • 2
  • 16
  • Can you paste here a `pip freeze` of the enviorment in your linux server enviorment? – lapinkoira Apr 21 '15 at 11:29
  • Babel==1.3 Flask==0.10.1 Flask-Babel==0.9 Flask-Login==0.2.11 Flask-Mail==0.9.1 Flask-SQLAlchemy==2.0 Flask-WTF==0.11 Flask-WhooshAlchemy==0.56 Jinja2==2.7.3 MarkupSafe==0.23 PAM==0.4.2 Pillow==2.3.0 SQLAlchemy==0.9.9 Tempita==0.5.2 Twisted-Core==13.2.0 Twisted-Web==13.2.0 WTForms==2.0.2 Werkzeug==0.10.4 Whoosh==2.6.0 adium-theme-ubuntu==0.3.4 argparse==1.2.1 blinker==1.3 chardet==2.0.1 colorama==0.2.5 coverage==3.7.1 decorator==3.4.2 flipflop==1.0 guess-language==0.2 html5lib==0.999 itsdangerous==0.24 pbr==0.10.8 pexpect==3.1 pyOpenSSL==0.13 pycurl==7.19.3 pygobject==3.12.0 pyserial==2.6 – Ryan McKinney Apr 21 '15 at 12:00
  • python-apt==0.9.3.5 python-debian==0.1.21-nmu2ubuntu2 pytz==2015.2 pyxdg==0.25 reportlab==3.0 requests==2.2.1 six==1.9.0 speaklater==1.3 sqlalchemy-migrate==0.9.6 sqlparse==0.1.15 system-service==0.1.6 unity-lens-photos==1.0 urllib3==1.7.1 virtualenv==12.1.1 wheel==0.24.0 wsgiref==0.1.2 xdiagnose==3.6.3build2 zope.interface==4.0.5 – Ryan McKinney Apr 21 '15 at 12:00
  • do you have sqlite3 installed in your python3.4? can you open a shell and run import sqlite3? – lapinkoira Apr 21 '15 at 12:13
  • 1
    SQLite3 is installed but it is preinstalled with Debian. I can call $sqlite3 but I cannot call it from within Python. When inside the virtual environment I can do sudo apt-get install sqlite3 and I get confirmation that the latest sqlite3 is installed. How do I got about including to be called from Python? – Ryan McKinney Apr 21 '15 at 12:43
  • I think the problem may be that SQLite3 is not a requiremtn in the Virtual Environment and therefor cant be imported. Ive tried installing it while in the virtual environment but it just confirms that it exists already and is up to date. which sqlite3 returns /usr/local/bin/sqlite3, should installing it within the environment location cure the issue? – Ryan McKinney Apr 21 '15 at 13:08
  • The problem is sqlite3 is a standard library for python but if your python installation cannot detect it because sqlite3 is not available then you could try `pip install pysqlite` – lapinkoira Apr 21 '15 at 13:42
  • As mentioned above when I do this i get an error Missing Parenthesis in call to 'print'. It suggests installing sphinx but this does not cure the issue. I think this error may be because sqlite is not available for Python 3 yet. – Ryan McKinney Apr 21 '15 at 13:43
  • Yeah, I didnt see that before, damn, that error means you cant install that into python3.x – lapinkoira Apr 21 '15 at 13:47
  • Ok, so basically you cant install it, and sqlite3 should be a standard library in your python3.4 So you have a problem with your python3.4 installation. Check this url http://stackoverflow.com/questions/27470530/how-to-import-sqlite3-in-my-python3-4-successfully – lapinkoira Apr 21 '15 at 13:48
  • lapinkoira your a saviour. That cured the issue and it is now running. Thanks a million – Ryan McKinney Apr 21 '15 at 13:58
  • `pip install pysqlite3` does it – Pe Dro Nov 03 '20 at 06:34

5 Answers5

4

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

Nishanth
  • 61
  • 3
3

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
Stefan
  • 2,164
  • 1
  • 23
  • 40
  • 1
    need to install sqlite3 ? – itzMEonTV Apr 21 '15 at 11:37
  • alternatively you can try to do a `pip install pysqlite2` – Stefan Apr 21 '15 at 11:38
  • Tried modifying the pysqlite.py to read from sqlite3 import dbapi2 as sqlite. This does not change it still gives me the same error and I have verified that I altered the correct file etc. – Ryan McKinney Apr 21 '15 at 11:57
  • 1
    If it raises `No Module named 'pysqlite2'` Then there has to be an import for it somewhere – Stefan Apr 21 '15 at 12:03
  • Could you solve this problem? I am having similar issues. I installed python3 with home-brew. Now when I try to import sqlite 3, i get similar error. I have sqlite3 installed. Just can't import it inside python3. – ac11 Jul 22 '15 at 14:03
0

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

 pip install pysqlite
navins
  • 3,429
  • 2
  • 28
  • 29
0

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/
rustberry
  • 1
  • 3
0

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

Vinay Kumar
  • 1,199
  • 13
  • 16