ImportError: No Module Named 'pysqlite2'

血红的双手。 提交于 2019-12-30 18:26:56

问题


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.


回答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



回答2:


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

 pip install pysqlite



回答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/


来源:https://stackoverflow.com/questions/29770906/importerror-no-module-named-pysqlite2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!