gpt4 book ai didi

python-3.x - Simplejson 错误 Python 3.3

转载 作者:行者123 更新时间:2023-12-05 01:17:15 26 4
gpt4 key购买 nike

我正在尝试运行一个导入 simplejson 的程序。当我在 Python 2.7 中运行它时没问题,但是当我在 Python 3.3 中运行它时它说:

File "C:\Python33\lib\simplejson__init__.py", line 111, in <module>
from decoder import JSONDecoder, JSONDecodeError
ImportError: No module named 'decoder'

最佳答案

无需使用外部simplejson库。 json module包含在 Python 3 标准库中的 完全相同的 模块,但作为 Python 发行版的一部分进行维护。引用自 simplejson PyPI page :

simplejson is the externally maintained development version of the json library included with Python 2.6 and Python 3.0, but maintains backwards compatibility with Python 2.5.

如果 json 不存在(仅适用于 Python 2.5,该库包含在 2.6 及更高版本中),请使用以下代码切换到 simplejson:

try:
import json
except ImportError:
# python 2.5
import simplejson as json

关于python-3.x - Simplejson 错误 Python 3.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14011355/

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