简体   繁体   English

没有名为 _sqlite3 的模块

[英]No module named _sqlite3

I am trying to run a Django app on my VPS running Debian 5. When I run a demo app, it comes back with this error:我正在尝试在运行DebianVPS上运行Django应用程序 5。当我运行演示应用程序时,它返回此错误:

  File "/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in     import_module
    __import__(name)

  File "/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
    raise ImproperlyConfigured, "Error loading %s: %s" % (module, exc)

ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that     order): No module named _sqlite3

Looking at the Python install, it gives the same error:查看 Python 安装,它给出了相同的错误:

Python 2.5.2 (r252:60911, May 12 2009, 07:46:31) 
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.5/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3
>>>

Reading on the web, I learn that Python 2.5 should come with all the necessary SQLite wrappers included.阅读 web,我了解到 Python 2.5 应该包含所有必要的SQLite包装器。 Do I need to reinstall Python, or is there another way to get this module up and running?我是否需要重新安装 Python,或者是否有其他方法可以启动并运行此模块?

It seems your makefile didn't include the appropriate .so file.您的 makefile 似乎没有包含适当的.so文件。 You can correct this problem with the steps below:您可以通过以下步骤更正此问题:

  1. Install sqlite-devel (or libsqlite3-dev on some Debian-based systems)安装sqlite-devel (或在一些基于 Debian 的系统上安装libsqlite3-dev
  2. Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make install使用./configure --enable-loadable-sqlite-extensions && make && sudo make install重新配置和重新编译 Python

Note笔记

The sudo make install part will set that python version to be the system-wide standard, which can have unforseen consequences. sudo make install部分会将 python 版本设置为系统范围的标准,这可能会产生不可预见的后果。 If you run this command on your workstation, you'll probably want to have it installed alongside the existing python, which can be done with sudo make altinstall .如果您在工作站上运行此命令,您可能希望将它现有的 python一起安装,这可以使用sudo make altinstall来完成。

I had the same problem (building python2.5 from source on Ubuntu Lucid), and import sqlite3 threw this same exception.我遇到了同样的问题(在 Ubuntu Lucid 上从源代码构建python2.5 ),并且import sqlite3抛出了同样的异常。 I've installed libsqlite3-dev from the package manager, recompiled python2.5, and then the import worked.我已经从包管理器安装了libsqlite3-dev ,重新编译了 python2.5,然后导入工作。

I had the same problem with Python 3.5 on Ubuntu while using pyenv .我在 Ubuntu 上使用 Python 3.5 时遇到了同样的问题pyenv

If you're installing the python using pyenv , it's listed as one of the common build problems .如果您使用pyenv安装 python,它会被列为常见的构建问题之一 To solve it, remove the installed python version, install the requirements (for this particular case libsqlite3-dev ), then reinstall the python version.要解决它,请删除已安装的 python 版本,安装需求(对于这种特殊情况libsqlite3-dev ),然后重新安装 python 版本。

This is what I did to get it to work.这就是我为使其正常工作所做的工作。

I am using pythonbrew(which is using pip) with python 2.7.5 installed.我正在使用安装了 python 2.7.5 的 pythonbrew(使用 pip)。

I first did what Zubair(above) said and ran this command:我首先按照 Zubair(above) 说的做并运行了这个命令:

sudo apt-get install libsqlite3-dev

Then I ran this command:然后我运行了这个命令:

pip install pysqlite

This fixed the database problem and I got confirmation of this when I ran:这解决了数据库问题,我在运行时得到了确认:

python manager.py syncdb
  1. Install the sqlite-devel package:安装sqlite-devel包:

    yum install sqlite-devel -y

  2. Recompile python from the source:从源代码重新编译python:

     ./configure make make altinstall

my python is build from source, the cause is missing options when exec configure python version:3.7.4我的python是从源代码构建的,原因是exec configure时缺少选项python版本:3.7.4

./configure --enable-loadable-sqlite-extensions --enable-optimizations
make
make install

fixed固定的

My _sqlite3.so is in /usr/lib/python2.5/lib-dynload/_sqlite3.so.我的 _sqlite3.so 在 /usr/lib/python2.5/lib-dynload/_sqlite3.so 中。 Judging from your paths, you should have the file /usr/local/lib/python2.5/lib-dynload/_sqlite3.so.从你的路径来看,你应该有文件/usr/local/lib/python2.5/lib-dynload/_sqlite3.so。

Try the following:请尝试以下操作:

find /usr/local -name _sqlite3.so

If the file isn't found, something may be wrong with your Python installation.如果未找到该文件,则您的 Python 安装可能有问题。 If it is, make sure the path it's installed to is in the Python path.如果是,请确保它的安装路径在 Python 路径中。 In the Python shell,在 Python 外壳中,

import sys
print sys.path

In my case, /usr/lib/python2.5/lib-dynload is in the list, so it's able to find /usr/lib/python2.5/lib-dynload/_sqlite3.so.在我的例子中,/usr/lib/python2.5/lib-dynload 在列表中,所以它能够找到 /usr/lib/python2.5/lib-dynload/_sqlite3.so。

I found lots of people meet this problem because the Multi-version Python, on my own vps (cent os 7 x64), I solved it in this way:我发现很多人遇到这个问题,因为我自己的 vps (cent os 7 x64) 上的多版本 Python,我是这样解决的:

  1. Find the file "_sqlite3.so"找到文件“_sqlite3.so”

     find / -name _sqlite3.so

    out: /usr/lib64/python2.7/lib-dynload/_sqlite3.so输出: /usr/lib64/python2.7/lib-dynload/_sqlite3.so

  2. Find the dir of python Standard library you want to use,找到你要使用的python标准库的目录,

    for me /usr/local/lib/python3.6/lib-dynload对我来说/usr/local/lib/python3.6/lib-dynload

  3. Copy the file:复制文件:

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

Finally, everything will be ok.最后,一切都会好起来的。

I recently tried installing python 2.6.7 on my Ubuntu 11.04 desktop for some dev work.我最近尝试在我的 Ubuntu 11.04 桌面上安装 python 2.6.7 以进行一些开发工作。 Came across similar problems to this thread.遇到了与此线程类似的问题。 I mamaged to fix it by:我通过以下方式修复它:

  1. Adjusting the setup.py file to include the correct sqlite dev path.调整 setup.py 文件以包含正确的 sqlite 开发路径。 Code snippet from setup.py: setup.py 中的代码片段:

     def sqlite_incdir: sqlite_dirs_to_check = [ os.path.join(sqlite_incdir, '..', 'lib64'), os.path.join(sqlite_incdir, '..', 'lib'), os.path.join(sqlite_incdir, '..', '..', 'lib64'), os.path.join(sqlite_incdir, '..', '..', 'lib'), '/usr/lib/x86_64-linux-gnu/' ]

    With the bit that I added being '/usr/lib/x86_64-linux-gnu/'.我添加的位是'/usr/lib/x86_64-linux-gnu/'。

  2. After running make I did not get any warnings saying the sqlite support was not built (ie, it built correctly :P ), but after running make install , sqlite3 still did not import with the same " ImportError: No module named _sqlite3" whe running "import sqlite3 ".运行 make 后,我没有收到任何警告说未构建 sqlite 支持(即,它正确构建 :P ),但在运行make install ,sqlite3 仍然没有导入相同的“ ImportError: No module named _sqlite3" whe running "import sqlite3 ”。

    So, the library was compiled, but not moved to the correct installation path, so I copied the .so file ( cp /usr/src/python/Python-2.6.7/build/lib.linux-x86_64-2.6/_sqlite3.so /usr/local/python-2.6.7/lib/python2.6/sqlite3/ — these are my build paths, you will probably need to adjust them to your setup).所以,库被编译,但没有移动到正确的安装路径,所以我复制了.so文件( cp /usr/src/python/Python-2.6.7/build/lib.linux-x86_64-2.6/_sqlite3.so /usr/local/python-2.6.7/lib/python2.6/sqlite3/这些是我的构建路径,你可能需要根据你的设置调整它们)。

Voila!瞧! SQLite3 support now works. SQLite3 支持现在有效。

This worked for me in Redhat Centos 6.5:这在 Redhat Centos 6.5 中对我有用:

yum install sqlite-devel
pip install pysqlite

sqlite3 ships with Python. sqlite3附带 Python。 I also had the same problem, I just uninstalled python3.6 and installed it again.我也有同样的问题,我只是卸载了python3.6并重新安装了它。

Uninstall existing python:卸载现有的python:

sudo apt-get remove --purge python3.6

Install python3.6:安装python3.6:

sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xvf Python-3.6.0.tar.xz
cd Python-3.6.0/
./configure
sudo make altinstall

For Python 3.7.8 with Redhat 7 or Centos 7.对于带有 Redhat 7 或 Centos 7 的 Python 3.7.8。

  • Install sqlite-devel安装 sqlite-devel
$ yum install sqlite-devel
  • Compile and install Python3 with sqllite extensions编译安装带有sqllite扩展的Python3
$ ./configure --enable-optimizations --enable-loadable-sqlite-extensions
$ make install

I have the problem in FreeBSD 8.1:我在 FreeBSD 8.1 中遇到了问题:

- No module named _sqlite3 -

It is solved by stand the port ----------靠站口解决 ----------

/usr/ports/databases/py-sqlite3

after this one can see:在这之后可以看到:

OK ----------
'>>>' import sqlite3 -----
'>>>' sqlite3.apilevel -----
'2.0'

是否安装了python-pysqlite2包?

sudo apt-get install python-pysqlite2

Checking your settings.py file.检查您的 settings.py 文件。 Did you not just write "sqlite" instead of "sqlite3" for the database engine?你不只是为数据库引擎写了“sqlite”而不是“sqlite3”吗?

Putting answer for anyone who lands on this page searching for a solution for Windows OS:为登陆此页面寻找 Windows 操作系统解决方案的任何人提供答案:

You have to install pysqlite3 or db-sqlite3 if not already installed.如果尚未安装,则必须安装 pysqlite3 或 db-sqlite3。 you can use following to install.您可以使用以下方法进行安装。

  • pip install pysqlite3 pip 安装 pysqlite3
  • pip install db-sqlite3 pip 安装 db-sqlite3

For me the issue was with DLL file of sqlite3.对我来说,问题出在 sqlite3 的 DLL 文件上。

Solution:解决方案:

  1. I took DLL file from sqlite site .我从sqlite 站点获取了 DLL 文件。 This might vary based on your version of python installation.这可能会因您的 Python 安装版本而异。

  2. I pasted it in the DLL directory of the env.我把它粘贴到 env 的 DLL 目录中。 for me it was "C:\\Anaconda\\Lib\\DLLs", but check for yours.对我来说,它是“C:\\Anaconda\\Lib\\DLLs”,但请检查你的。 放置DLL文件前后

你必须在centos或redhat并且自己编译python,这是python的错误,在你的python源代码目录中执行此操作并在下面执行此操作

curl -sk https://gist.github.com/msabramo/2727063/raw/59ea097a1f4c6f114c32f7743308a061698b17fd/gistfile1.diff | patch -p1

I got the same problem, nothing worked for me from the above ans but now I fixed it by我遇到了同样的问题,上面的答案对我没有任何作用,但现在我通过

just remove python.pip and sqlite3 and reinstall只需删除python.pipsqlite3并重新安装

  1. sudo apt-get remove python.pip
  2. sudo apt-get remove sqlite3

now install it again现在重新安装

  1. sudo apt-get install python.pip
  2. sudo apt-get install sqlite3

in my case while installing sqlite3 again it showed some error then I typed就我而言,在再次安装sqlite3时,它显示了一些错误,然后我输入了

  1. sqlite3

on terminal to check if it was removed or not and it started unpacking it在终端上检查它是否被移除并开始拆包

once the sqlite3 is installed fireup terminal and write一旦安装了sqlite3 fireup终端并写入

  1. sqlite3
  2. database.db (to create a database) database.db (创建数据库)

I'm sure this will definitely help you我相信这肯定会帮助你

I was disappointed this issue still exist till today.我很失望这个问题直到今天仍然存在。 As I have recently been trying to install vCD CLI on CentOS 8.1 and I was welcomed with the same error when tried to run it.因为我最近一直在尝试在 CentOS 8.1 上安装 vCD CLI,并且在尝试运行它时遇到了同样的错误。 The way I had to resolve it in my case is as follow:在我的情况下,我必须解决的方法如下:

  • Install SQLite3 from scratch with the proper prefix使用正确的前缀从头开始安装 SQLite3
  • Make clean my Python Installation清理我的 Python 安装
  • Run Make install to reinstall Python运行 Make install 重新安装 Python

As I have been doing this to create a different blogpost about how to install vCD CLI and VMware Container Service Extension.因为我一直这样做是为了创建一篇关于如何安装 vCD CLI 和 VMware Container Service Extension 的不同博客文章。 I have end up capturing the steps I used to fix the issue and put it in a separate blog post at:我最终捕获了我用来解决问题的步骤并将其放在单独的博客文章中:

http://www.virtualizationteam.com/cloud/running-vcd-cli-fail-with-the-following-error-modulenotfounderror-no-module-named-_sqlite3.html http://www.virtualizationteam.com/cloud/running-vcd-cli-fail-with-the-following-error-modulenotfounderror-no-module-named-_sqlite3.html

I hope this helpful, as while the tips above had helped me get to a solution, I had to combine few of them and modify them a bit.我希望这有帮助,因为虽然上面的提示帮助我找到了解决方案,但我不得不将其中的几个组合起来并稍微修改一下。

Download sqlite3:下载 sqlite3:

wget http://www.sqlite.org/2016/sqlite-autoconf-3150000.tar.gz

Follow these steps to install:请按照以下步骤进行安装:

$tar xvfz sqlite-autoconf-3071502.tar.gz
$cd sqlite-autoconf-3071502
$./configure --prefix=/usr/local
$make install

如果您使用的是 FreeBSD,请尝试像这样安装 sqlite。

pkg install py27-sqlite3-2.7.10_6

I had the same problem after installing Python 3.8.11 using asdf使用asdf安装 Python 3.8.11 后我遇到了同样的问题

To fix the issue:要解决此问题:

I had to install libsqlite3-dev我必须安装libsqlite3-dev

sudo apt-get install libsqlite3-dev

Then uninstall Python via asdf然后通过asdf卸载Python

asdf uninstall python 3.8.11

And install Python again via asdf并通过asdf再次安装 Python

asdf install python 3.8.11

The following worked for Python 3.9 with a virtual environment:以下适用于具有虚拟环境的 Python 3.9:

  1. Install the sqlite3 library.安装 sqlite3 库。

     sudo apt-get install libsqlite3-dev<\/code><\/pre><\/li>
  2. Activate the Python virtual environment.激活 Python 虚拟环境。

     source env\/bin\/activate<\/code><\/pre><\/li>
  3. Copy the sqlite3 file into the Python virtual environment and rename it to support Python 3.9.将 sqlite3 文件复制到 Python 虚拟环境中并重命名以支持 Python 3.9。

     cp \/usr\/lib\/python3.8\/lib-dynload\/_sqlite3.cpython-38-x86_64-linux-gnu.so .\/env\/lib\/python3.9\/site-packages mv .\/env\/lib\/python3.9\/site-packages\/_sqlite3.cpython-38-x86_64-linux-gnu.so .\/env\/lib\/python3.9\/site-packages\/_sqlite3.cpython-39-x86_64-linux-gnu.so<\/code><\/pre><\/li><\/ol>

    Note, we're renaming 38 to 39 in the file name to support Python 3.9.<\/em>请注意,我们将文件名中的 38 重命名为 39 以支持 Python 3.9。<\/em>

    "

I faced this issue with multiple python dependent package while setup in python virtual enironment in Ubuntu .It is because of sqlite binding for our python .我在 python 依赖 package 中设置 python 虚拟环境时遇到了这个问题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完成了,现在你可以安装包了

I ran into this same problem on a NetBSD server.我在 NetBSD 服务器上遇到了同样的问题。 A missing .so file needed to be installed using pkgin .需要使用pkgin安装缺少的.so文件。 To identify what package to install, I ran为了确定要安装什么 package,我跑了

pkgin search sqlite

which had lots of results, including结果很多,包括

...

py38-aiosqlite-0.17.0nb1  Async bridge to the standard sqlite3 module
py38-apsw-3.37.0nb2  Python wrapper for SQLite
py38-peewee-3.15.0   Small, expressive ORM for PostgreSQL, MySQL and SQLite
py38-sqlite3-3.8.13nb22  Built-in sqlite support for Python 2.5 and up
py39-aiosqlite-0.17.0nb1  Async bridge to the standard sqlite3 module
py39-apsw-3.37.0nb2  Python wrapper for SQLite
py39-peewee-3.15.0   Small, expressive ORM for PostgreSQL, MySQL and SQLite
py39-sqlite3-3.9.13nb22  Built-in sqlite support for Python 2.5 and up
...

(and other python versions as well). (以及其他 python 版本)。 I'm using python 3.9, so py39-sqlite3-3.9.13nb22 was the correct choice in my case.我使用的是 python 3.9,所以py39-sqlite3-3.9.13nb22是我的正确选择。 Running跑步

sudo pkgin install py39-sqlite3-3.9.13nb22

fixed the issue for me.为我解决了这个问题。

你需要在你的python环境中安装pysqlite

    $ pip install pysqlite

Try copying _sqlite3.so so that Python can find it.尝试复制_sqlite3.so以便 Python 可以找到它。

It should be as simple as:它应该很简单:

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

Trust me, try it.相信我,试试吧。

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

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