Tango with Django:没有名为_sqlite3的模块

2024-03-28 11:25:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道已经有很多人遇到了这个问题,但是我已经花了三个小时检查了我能找到的每一个环节,我还没有找到一个适合我的解决方案。我很抱歉不得不做这条线,但我没有其他选择。在

我一直在用探戈做Django,在我进入这个部分之前,一切都非常顺利:http://www.tangowithdjango.com/book/chapters/models.html#creating-and-synchronising-the-database

执行syncdb命令时,Python无法识别sqlite3。所以我决定用一个简单的导入测试来验证这一点:

rob@rob-Latitude-E5400:~/code/tango_with_django_project$ python
Python 2.7.5 (default, Sep 21 2014, 16:23:05) 
[GCC 4.6.3] 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 "/home/rob/.pythonbrew/pythons/Python-2.7.5/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/home/rob/.pythonbrew/pythons/Python-2.7.5/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3
>>> 

很多人在网上也有同样的问题。这家伙

https://stackoverflow.com/a/1210746/694855

给出了一些建议,以找到\u sqlite3.so,并将目录放在PYTHONPATH中。我再次运行syncdb命令,得到的结果是:

^{pr2}$

现在我被卡住了。我在谷歌上搜索了最后一个错误,没找到多少。关于我的Python是如何用不同的Unicode编译的。但这并不能告诉我如何解决这个问题。在

谢谢你的阅读和帮助。在


Tags: inpyimport命令comhomelibline
1条回答
网友
1楼 · 发布于 2024-03-28 11:25:30

固定的。我看到了这样的反应:

https://stackoverflow.com/a/19748196/694855

但是,当我运行pip install pysqlite时,我收到了以下消息:

[snipped]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -DSQLITE_OMIT_LOAD_EXTENSION=1 -I/usr/include/python2.7 -c src/module.c -o build/temp.linux-x86_64-2.7/src/module.o

In file included from src/module.c:24:0:

src/connection.h:26:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1
[snipped]

原来我没有安装Python开发文件。我从这篇文章中找到了答案:http://www.linuxquestions.org/questions/linux-software-2/apparent-gcc-error-when-building-pysqlite-697318/#post3408711

所以我跑了:sudo apt-get install python-dev

然后我可以成功运行:pip install pysqlite

最后,当我运行Django教程中的命令时:./manage.py syncdb

我得到正确的输出。我希望这对其他人有帮助,因为这个解决方案很复杂,很难在网上找到。在

相关问题 更多 >