问题:没有名为_sqlite3的模块

我试图在运行Debian 5的VPS上运行Django应用程序。运行演示应用程序时,它返回此错误:

  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

查看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
>>>

在网上阅读后,我了解到Python 2.5应该附带所有必需的SQLite包装器。我需要重新安装Python,还是有另一种方法来启动和运行此模块?

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:

  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 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. Do I need to reinstall Python, or is there another way to get this module up and running?


回答 0

您的makefile文件似乎没有包含适当的.so文件。您可以按照以下步骤纠正此问题:

  1. 安装sqlite-devel(或libsqlite3-dev在某些基于Debian的系统上)
  2. 使用以下命令重新配置和重新编译Python ./configure --enable-loadable-sqlite-extensions && make && sudo make install

注意

sudo make install部分将把python版本设置为系统范围的标准,这可能会产生无法预料的后果。如果您在工作站上运行此命令,则可能希望将其现有python 一起安装,可以使用来完成sudo make altinstall

It seems your makefile didn’t include the appropriate .so file. You can correct this problem with the steps below:

  1. Install sqlite-devel (or libsqlite3-dev on some Debian-based systems)
  2. Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make install

Note

The sudo make install part will set that python version to be the system-wide standard, which can have unforseen consequences. 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.


回答 1

我遇到了同样的问题(python2.5从Ubuntu Lucid上的源代码构建),并import sqlite3抛出了同样的异常。我已经libsqlite3-dev从软件包管理器安装了,重新编译了python2.5,然后导入工作了。

I had the same problem (building python2.5 from source on Ubuntu Lucid), and import sqlite3 threw this same exception. I’ve installed libsqlite3-dev from the package manager, recompiled python2.5, and then the import worked.


回答 2

使用pyenv时,我在Ubuntu上的Python 3.5遇到了相同的问题。

如果您使用pyenv安装python ,则将其列为常见的构建问题之一。要解决此问题,请删除已安装的python版本,安装要求(针对此特殊情况libsqlite3-dev),然后重新安装python版本。

I had the same problem with Python 3.5 on Ubuntu while using pyenv.

If you’re installing the python using pyenv, it’s listed as one of the common build problems. To solve it, remove the installed python version, install the requirements (for this particular case libsqlite3-dev), then reinstall the python version.


回答 3

这就是我为使其正常工作所做的。

我正在使用安装了python 2.7.5的pythonbrew(正在使用pip)。

我首先执行了Zubair(上面)所说的,然后运行了以下命令:

sudo apt-get install libsqlite3-dev

然后我运行以下命令:

pip install pysqlite

这解决了数据库问题,我在运行时得到了确认:

python manager.py syncdb

This is what I did to get it to work.

I am using pythonbrew(which is using pip) with python 2.7.5 installed.

I first did what Zubair(above) said and ran this command:

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

回答 4

  1. 安装sqlite-devel软件包:

    yum install sqlite-devel -y

  2. 从源代码重新编译python:

    ./configure
    make
    make altinstall
  1. Install the sqlite-devel package:

    yum install sqlite-devel -y

  2. Recompile python from the source:

    ./configure
    make
    make altinstall
    

回答 5

我的_sqlite3.so位于/usr/lib/python2.5/lib-dynload/_sqlite3.so中。从您的路径来看,您应该拥有文件/usr/local/lib/python2.5/lib-dynload/_sqlite3.so。

尝试以下方法:

find /usr/local -name _sqlite3.so

如果找不到该文件,则说明您的Python安装可能有问题。如果是,请确保其安装路径在Python路径中。在Python Shell中,

import sys
print sys.path

就我而言,/usr/lib/python2.5/lib-dynload在列表中,因此它可以找到/usr/lib/python2.5/lib-dynload/_sqlite3.so。

My _sqlite3.so is in /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.

Try the following:

find /usr/local -name _sqlite3.so

If the file isn’t found, something may be wrong with your Python installation. If it is, make sure the path it’s installed to is in the Python path. In the Python shell,

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.


回答 6

我最近尝试在Ubuntu 11.04桌面上安装python 2.6.7,以进行一些开发工作。遇到了与此线程类似的问题。我想通过以下方式修复它:

  1. 调整setup.py文件以包含正确的sqlite开发路径。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/'
    ]

    我添加的位是’/ usr / lib / x86_64-linux-gnu /’。

  2. 运行make之后,我没有收到任何警告,提示未构建sqlite支持(即,它正确构建了:P),但是运行后make install,sqlite3仍未使用相同的“ ImportError: No module named _sqlite3" whe running "import sqlite3” 导入。

    因此,该库已编译,但未移至正确的安装路径,因此我复制了该.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/这些是我的构建路径,您可能需要根据设置进行调整)。

瞧!现在支持SQLite3。

I recently tried installing python 2.6.7 on my Ubuntu 11.04 desktop for some dev work. 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. Code snippet from 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/’.

  2. After running make I did not get any warnings saying the sqlite support was not built (i.e., 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“.

    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).

Voila! SQLite3 support now works.


回答 7

我发现很多人都遇到了这个问题,因为在我自己的vps(cent os 7 x64)上,Multi-version Python是通过以下方式解决的:

  1. 找到文件“ _sqlite3.so”

    find / -name _sqlite3.so

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

  2. 找到您要使用的python标准库的目录,

    为了我 /usr/local/lib/python3.6/lib-dynload

  3. 复制文件:

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

最后,一切都会好的。

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:

  1. Find the file “_sqlite3.so”

    find / -name _sqlite3.so
    

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

  2. Find the dir of python Standard library you want to use,

    for me /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.


回答 8

这在Redhat Centos 6.5中对我有用:

yum install sqlite-devel
pip install pysqlite

This worked for me in Redhat Centos 6.5:

yum install sqlite-devel
pip install pysqlite

回答 9

我的python是从源代码构建的,原因是在exec配置python版本时缺少选项:3.7.4

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

固定

my python is build from source, the cause is missing options when exec configure python version:3.7.4

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

fixed


回答 10

我在FreeBSD 8.1中有问题:

- No module named _sqlite3 -

通过站立端口解决———-

/usr/ports/databases/py-sqlite3

在此之后可以看到:

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

I have the problem in 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'

回答 11

是否安装了python-pysqlite2软件包?

sudo apt-get install python-pysqlite2

Is the python-pysqlite2 package installed?

sudo apt-get install python-pysqlite2

回答 12

检查您的settings.py文件。您是否不仅为数据库引擎编写了“ sqlite”而不是“ sqlite3”?

Checking your settings.py file. Did you not just write “sqlite” instead of “sqlite3” for the database engine?


回答 13

sqlite3Python附带。我也有同样的问题,我只是卸载python3.6并重新安装了它。

卸载现有的python:

sudo apt-get remove --purge 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

sqlite3 ships with Python. I also had the same problem, I just uninstalled python3.6 and installed it again.

Uninstall existing python:

sudo apt-get remove --purge python3.6

Install 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

回答 14

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

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

you must be in centos or redhat and compile python yourself, it is python‘s bug do this in your python source code dir and do this below

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

回答 15

我遇到了同样的问题,上述问题对我没有任何帮助,但是现在我通过

只是删除python.pipsqlite3并重新安装

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

现在再次安装

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

在我的情况下sqlite3再次安装时它显示了一些错误,然后我键入

  1. sqlite3

在终端上检查是否已卸下,然后开始拆箱

一旦sqlite3安装了启动终端并写入

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

我相信这一定会对您有帮助

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

  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

  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

  1. sqlite3
  2. database.db (to create a database)

I’m sure this will definitely help you


回答 16

为登录此页面的任何人提供答案,以寻找适用于Windows OS的解决方案:

如果尚未安装pysqlite3或db-sqlite3,则必须安装。您可以使用以下安装。

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

对我来说,问题在于sqlite3的DLL文件。

解:

  1. 我从sqlite网站上获取了DLL文件。这可能会因您安装的python版本而异。

  2. 我将其粘贴到env的DLL目录中。对我来说,它是“ C:\ Anaconda \ Lib \ DLLs”,但请检查您的。 放置DLL文件前后

Putting answer for anyone who lands on this page searching for a solution for Windows OS:

You have to install pysqlite3 or db-sqlite3 if not already installed. you can use following to install.

  • pip install pysqlite3
  • pip install db-sqlite3

For me the issue was with DLL file of sqlite3.

Solution:

  1. I took DLL file from sqlite site. This might vary based on your version of python installation.

  2. I pasted it in the DLL directory of the env. for me it was “C:\Anaconda\Lib\DLLs”, but check for yours. Before and After placing DLL file


回答 17

令我感到失望的是,这个问题一直存在到今天。由于我最近一直在尝试在CentOS 8.1上安装vCD CLI,因此在尝试运行它时出现相同的错误,对此我表示欢迎。在我的情况下,我必须解决的方法如下:

  • 使用适当的前缀从头开始安装SQLite3
  • 清理我的Python安装
  • 运行Make install重新安装Python

正如我一直在做的那样,以创建有关如何安装vCD CLI和VMware Container Service Extension的不同博客文章。我最终捕获了用于解决此问题的步骤,并将其放在单独的博客文章中,网址为:

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

我希望这会有所帮助,因为尽管上面的提示帮助我找到了解决方案,但我不得不将其中的几个结合起来并进行一些修改。

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. The way I had to resolve it in my case is as follow:

  • Install SQLite3 from scratch with the proper prefix
  • Make clean my Python Installation
  • Run Make install to reinstall Python

As I have been doing this to create a different blogpost about how to install vCD CLI and 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

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.


回答 18

下载sqlite3:

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

请按照以下步骤进行安装:

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

Download 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

回答 19

您需要在python环境中安装pysqlite

    $ pip install pysqlite

You need to install pysqlite in your python environment:

    $ pip install pysqlite

回答 20

尝试复制 _sqlite3.so以便Python可以找到它。

它应该很简单:

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

相信我,尝试一下。

Try copying _sqlite3.so so that Python can find it.

It should be as simple as:

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

Trust me, try it.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。