1

I know there are already many people with this problem, but I've spent the last three hours going over every link I can find and I haven't been able to find a solution that works for me. I'm embarrassed to have to make this thread but I have no other option.

I've been doing Django with Tango, everything was running very smoothly until I got to this section: http://www.tangowithdjango.com/book/chapters/models.html#creating-and-synchronising-the-database

When doing the syncdb command, Python didn't recognize sqlite3. So I decided to verify this with a simple import test:

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

Lots of people had this same problem online. This guy

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

Gave some advice to find the _sqlite3.so, and put the directory in the PYTHONPATH. I ran the syncdb command again, and got this:

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

Now I'm stuck. I Googled the last error and couldn't find much. Something about how my Python was compiled with a different Unicode. That doesn't tell me much on how to fix the problem though.

Thanks for reading and the help.

1 Answer 1

0

Fixed. I saw this response:

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

However, when I ran pip install pysqlite I received this:

[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]

It turns out that I didn't have the Python development files installed. I figured this out from this post: http://www.linuxquestions.org/questions/linux-software-2/apparent-gcc-error-when-building-pysqlite-697318/#post3408711

So I ran: sudo apt-get install python-dev

Then I could successfully run: pip install pysqlite

Finally, now when I run the command from the Django tutorial: ./manage.py syncdb

I get the correct output. I hope this helps someone else, since this solution was convoluted and quite hard to find online.

1
  • I'm not sure why you're bothering to install pysqlite in Python 2.7 as sqlite3 is basically the same, and part of the standard library. You should just rebuild Python after installing the necessary deps to get it working. I agree it's pretty baffling that the Python build process doesn't choke and die when it can't build it's own standard library.
    – Nick T
    Oct 6, 2014 at 1:09

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.