gpt4 book ai didi

python - 无法导入名称 simplejson - 安装 simplejson 后

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

我有 Django 版本 1.7 和 Python 版本 2.7.5 - 我使用 pip install simplejson 和 apt-get install python-simplejson 命令来解决这个问题,但它仍然显示这个异常。 Django 和 Python 之间是否存在任何兼容性问题,或者解决此异常的解决方案是什么:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/root/test_env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/root/test_env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/root/test_env/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/root/test_env/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/root/test_env/local/lib/python2.7/site-packages/django/apps/config.py", line 123, in create
import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/test_env/local/lib/python2.7/site-packages/extdirect.django-0.3-py2.7.egg/extdirect/django/__init__.py", line 3, in <module>
from providers import ExtRemotingProvider, ExtPollingProvider
File "/root/test_env/local/lib/python2.7/site-packages/extdirect.django-0.3-py2.7.egg/extdirect/django/providers.py", line 4, in <module>
from django.utils import simplejson
ImportError: cannot import name simplejson

最佳答案

您的代码与您使用的 Django 版本不兼容。

Django 过去常常在 django.utils 中附带 simplejson,但这是 removed in Django 1.5 :

django.utils.simplejson

Since Django 1.5 drops support for Python 2.5, we can now rely on the json module being available in Python’s standard library, so we’ve removed our own copy of simplejson. You should now import json instead of django.utils.simplejson.

Unfortunately, this change might have unwanted side-effects, because of incompatibilities between versions of simplejson – see the backwards-incompatible changes section. If you rely on features added to simplejson after it became Python’s json, you should import simplejson explicitly.


您应该将 extdirectproviders.py 中的代码更新为 import json,或者使用它设计的 Django 版本一起工作。

关于python - 无法导入名称 simplejson - 安装 simplejson 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28048943/

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