尝试 运行 Django 测试,加载 pysqlite2 或 sqlite3 时出错?

Trying to run Django tests, get error loading either pysqlite2 or sqlite3?

我正在尝试 运行 测试一个不是我的项目,当我 python manage.py 测试时,我得到

raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'

我已经安装了 sqlite3 和 pysqlite2 以及所有的 dev-lib 包,它告诉我要求已经满足。我在虚拟环境之外安装了它们,我相信这是我的问题,但我害怕使用 sudo apt-get remove 因为上次我使用这个命令我几乎删除了我的整个 Ubuntu。有什么建议吗?

  • 在你的虚拟环境中:

    pip install pysqlite2
    

注意:sqlite3模块包含在标准库中(自Python 2.5)。

编辑:尝试安装以下内容:

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install libsqlite3-dev libsqlite3

因为我正在使用 Ubuntu,所以我从终端安装了 python,而不是从 source。我做的安装肯定没有包含sqlite3.

我为解决问题采取的步骤:

source下载您需要的Python版本的源文件。将文件夹解压到某处,cd 进入文件夹,

./configure
make
make install

解决了我的问题。