12

I'm trying to build a realtime chat app in Django(1.7.1). It seems that I needed to install Redis and ishout.js. So I installed them by following the instructions.

After making the project in Django, I put 'drealtime' under the INSTALLED_APPS, and put:

'drealtime.middleware.iShoutCookieMiddleware' 

right above :

'django.contrib.sessions.middleware.SessionMiddleware' 

under the MIDDLEWARE_CLASSES as it was saying. And I put the command like

python manage.py startapp example

but still I have this import error message:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/apps/config.py", line 87, in create
    module = import_module(entry)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/drealtime/__init__.py", line 4, in <module>
    from django.utils import simplejson as json

After I searched through the Django official site, I found simplejson is no longer used and removed from new Django. I don't know why this is happening. Please give any feedback on this issue and possible remedy to tackle this issue.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Sungpah Lee
  • 1,003
  • 1
  • 13
  • 31

3 Answers3

14

You are using an outdated version of django-realtime.

Upgrade it to the latest version, they fixed the 1.7 compatibility:

pip install django-realtime --upgrade

If the error persists, install directly from github, master branch:

$ pip install git+https://github.com/anishmenon/django-realtime.git --upgrade

FYI, the fix:

try:
    from django.utils import simplejson as json
except:
    import simplejson as json

Bare exception clause - zen programmer inside is killing me whispering except ImportError, except ImportError, except..

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Unfortunately, I don't have any view.py file yet because when I tried to make the application, this error popped up, not allowing me to have any view.py file. The __init__.py file is empty for now. – Sungpah Lee Jan 09 '15 at 07:33
  • @SungpahLee nono, I mean update the `django-realtime` package, reinstall it to the latest version: `pip install django-realtime --upgrade`. – alecxe Jan 09 '15 at 07:34
  • rescomp-14-285794:realpro sungpah$ pip install django-realtime --upgrade Requirement already up-to-date: django-realtime in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages Cleaning up... rescomp-14-285794:realpro sungpah$ – Sungpah Lee Jan 09 '15 at 07:36
  • @SungpahLee see the updated answer please (install from github). – alecxe Jan 09 '15 at 07:37
  • And still I have a same problem when trying to make an app. When I installed django-realtime, the command was like "pip install django-realtime" – Sungpah Lee Jan 09 '15 at 07:37
  • Awesome. Now the app is installed!!!!!!Thanks so much. I was bogged down to this issue for 6 hours.. – Sungpah Lee Jan 09 '15 at 07:39
  • 1+ for try..except section, really helpful – MegaBytes Apr 24 '15 at 07:38
5

I think the above answers are workarounds.

Django used to ship with simplejson in django.utils, but this was removed in Django 1.5 because json module being available in Python’s standard library.

So you should now import json instead of from django.utils import simplejson, and make necessary changes where simplejson methods are called.

Frank Fang
  • 151
  • 2
  • 7
2

This is a bug in the application itself; unfortunately the error still persists in the master branch at git.

I submitted a pull request to fix the error; in the meanwhile you can do the following:

pip uninstall django-realtime
pip install git+https://github.com/burhan/django-realtime.git@import-fix
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284