How to solve the ImportError: cannot import name simplejson in Django

后端 未结 3 1444
长情又很酷
长情又很酷 2021-02-19 20:44

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.

Aft

相关标签:
3条回答
  • 2021-02-19 21:03

    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.

    0 讨论(0)
  • 2021-02-19 21:12

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

    0 讨论(0)
  • 2021-02-19 21:16

    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
    
    0 讨论(0)
提交回复
热议问题