我知道已经有很多人遇到过这个问题,但是我花了最后三个小时来查看我能找到的每个链接,但我找不到适合我的解决方案。我不好意思制作这个帖子,但我别无选择。
我一直在用Tango做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
给出一些建议来找到_sqlite3.so,并将目录放在PYTHONPATH中。我再次运行了syncdb命令,得到了这个:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 263, in fetch_command
app_name = get_commands()[subcommand]
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 109, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 49, in _setup
self._configure_logging()
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 71, in _configure_logging
from django.utils.log import DEFAULT_LOGGING
File "/usr/local/lib/python2.7/dist-packages/django/utils/log.py", line 6, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 11, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/usr/local/lib/python2.7/dist-packages/django/http/__init__.py", line 2, in <module>
from django.http.request import (HttpRequest, QueryDict, UnreadablePostError,
File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 8, in <module>
from io import BytesIO
File "/home/rob/.pythonbrew/pythons/Python-2.7.5/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: /usr/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyUnicodeUCS4_EncodeUTF32
现在我被卡住了。我用谷歌搜索了最后一个错误,找不到多少。关于我的Python是如何用不同的Unicode编译的。这并没有告诉我如何解决这个问题。
感谢阅读和帮助。
答案 0 :(得分:0)
固定。我看到了这个回应:
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
我得到了正确的输出。我希望这有助于其他人,因为这个解决方案很复杂,很难在网上找到。