简体   繁体   English

导入错误:没有名为“pysqlite2”的模块

[英]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.我在 Python 中编写了一个程序,该程序是在 windows 上完成的。在 windows 测试环境中工作正常。 Now I am setting up a linux server to internally host the program.现在我正在设置一个 linux 服务器来内部托管程序。 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?据我了解 sqlite 要么不兼容,要么有兼容性问题?

Another issue that I think is directly related is when inside the virtual environment and I try pip3.4 install pysqlite i get我认为直接相关的另一个问题是在虚拟环境中,我尝试 pip3.4 install pysqlite 我得到

SyntaxError: Missing Parenthesis in call to 'Print

Its suggests install Sphinx which I did but did not cure.它建议安装我做过但没有治愈的 Sphinx。

I think these two issues are directly related and by curing ine should be able to cure the other.我认为这两个问题是直接相关的,通过治愈 in 应该能够治愈另一个。

You could probably just use sqlite3 which is now part of the standard library and should work exactly the same as pysqlite2 does.您可能只使用sqlite3 ,它现在是标准库的一部分,应该与 pysqlite2 的工作方式完全相同。 You can try to modify the file mentioned from:您可以尝试修改提到的文件:

from pysqlite2 import dbapi2 as sqlite

to

from sqlite3 import dbapi2 as sqlite

You can do the below changes to make your jupyter notebook work您可以进行以下更改以使您的 jupyter notebook 正常工作

Replace the file “C:\Windows\System32\sqlite3.dll” by “C:\Users\username\anaconda3\Library\bin\sqlite3.dll”将文件“C:\Windows\System32\sqlite3.dll”替换为“C:\Users\username\anaconda3\Library\bin\sqlite3.dll”

This will make jupyter notebook work这将使 jupyter notebook 工作

Try pip search sqlite , you may find many candidates.试试pip search sqlite ,你可能会发现很多候选人。 Pick something like this one:选择这样的一个:

 pip install pysqlite

For people on CentOS 6 and Python 2.6:对于使用 CentOS 6 和 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.直接执行pip install pysqlite会导致 gcc 错误,你必须先yum install sqlite-devel ,然后才能安装 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:之后,如果您使用的 Python 版本与 CentOS 6 附带的 Python 2.6 不同, ImportError可能仍然存在。我收到的错误消息如下:

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.这是一个连接问题,下面复制从旧Py2.6目录编译库文件Py2.7解决我的问题,因为灵感Github上讨论。

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/

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 .我在安装时遇到了多个 python 依赖 package 的问题,特别是在 python 虚拟环境中安装 jupyter 笔记本时Ubuntu 。这是因为sqlite绑定了我们的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.我通过 --enable-loadable-sqlite-extensions=yes 解决了它 1.) 首先找到您用于创建虚拟环境的 python 或 python 版本。 I have used python3.8 eg我用过 python3.8 例如

$ 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.注意: pytho会有很多package检查。 you will find configure file for each python version, now use specific python version你会找到每个 python 版本的配置文件,现在使用特定的 python 版本

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 eg Go the folder where you want to create the virtual env现在,使用 python 版本创建您的虚拟环境,例如 Go 您要在其中创建虚拟环境的文件夹

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

Its done, now you can install packages完成了,现在你可以安装包了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM