12

I'm currently working through the official Django tutorial using version 1.6.1 and version 2.7.5 of python on OSX. I'm working on part 2, which is the admin interface. When I attempt to go to /admin/polls/poll/, I get the following error report:

ImproperlyConfigured at /admin/polls/poll/
This query requires pytz, but it isn't installed.
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/polls/poll/
Django Version: 1.6.1
Exception Type: ImproperlyConfigured
Exception Value:    
This query requires pytz, but it isn't installed.
Exception Location: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py in datetime_trunc_sql, line 196
Python Executable:  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.5

I attempted to install pytz by installing pip (which required installing setuptools) but this made no difference. Also, I am going through this tutorial for a second time, and I know I didn't run into this problem a month ago. Could updating to Mavericks have caused some problem?

John D.
  • 2,521
  • 3
  • 24
  • 45

4 Answers4

17

I was also getting the same error. I installed pytz

$ pip install pytz

and then i restarted the server. The exception is no more now.

prashantsahni
  • 2,128
  • 19
  • 20
14

After continuing to search for django and pytz, I found the 1.6 Django release notes, which mention that you must now install pytz to work with Sqlite3 if USE_TZ=True in your settings.py.

I don't know what effect USE_TZ has on your application, but setting that value to False allows me to proceed in the tutorial. I would hope that the Django tutorial is updated to reflect this change.

John D.
  • 2,521
  • 3
  • 24
  • 45
  • 3
    USE_TZ=True makes the dates and times timezone aware. This is usually required if users from different timezones need to use your app. More details here: https://docs.djangoproject.com/en/dev/topics/i18n/timezones/ – arocks Jan 13 '14 at 06:02
  • 3
    If the default for USE_TZ is true (and probably required for most apps), should pytz be included with Django? BTW I finally got pytz working, and was able to re-enable USE_TZ. On Mac, I did: "sudo easy_install pip" then "sudo pip install pytz" and this time, it seemed to work fine. I was manually installing setuptools and pip from .py scripts on their respective sites, and nothing seemed to work. – John D. Jan 13 '14 at 16:16
  • It was running fine for me until I upgraded to from Django 1.4 to 1.8, does it means USE_TZ wasn't previously enabled and now it is enabled by default? I don't remember enabling it or having any problems with it before. – BluePython Mar 30 '16 at 04:17
3

The solution is very simple..

pip install pytz

and then stop and restart your server

Transformer
  • 3,642
  • 1
  • 22
  • 33
2

I had same error, then I installed pytz with pip install pytz and again had same error until I restarted WSGI instance. (eg. touching wsig.py (touch wsgi.py) or restarting apache (apache2ctl restart)

pom
  • 423
  • 5
  • 10