gpt4 book ai didi

python - 如何解决 ImportError : cannot import name simplejson in Django

转载 作者:太空狗 更新时间:2023-10-29 17:41:50 25 4
gpt4 key购买 nike

我正在尝试在 Django(1.7.1) 中构建一个实时聊天应用程序。看来我需要安装 Redis 和 ishout.js。所以我按照说明安装了它们。

在 Django 中制作项目后,我将 'drealtime' 放在 INSTALLED_APPS 下,并放置:

'drealtime.middleware.iShoutCookieMiddleware' 

右上方:

'django.contrib.sessions.middleware.SessionMiddleware' 

如其所说,在 MIDDLEWARE_CLASSES 下。我把命令放在

python manage.py startapp example

但我仍然收到此导入错误消息:

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

在Django官方网站上搜索后,我发现simplejson不再被使用并从新的Django中移除。我不知道为什么会这样。请提供有关此问题的任何反馈以及解决此问题的可能补救措施。

最佳答案

您使用的是 django-realtime 的过时版本。

升级到最新版本,他们fixed the 1.7 compatibility :

pip install django-realtime --upgrade

如果还是报错,直接从github安装,master分支:

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

仅供引用,修复:

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

Bare exception clause - zen programmer inside 正在窃窃私语except ImportError, except ImportError, except..

关于python - 如何解决 ImportError : cannot import name simplejson in Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27855731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com