【发布时间】:2017-11-26 14:20:42
【问题描述】:
我使用 python 3.4.3 设置 virtualenv 并尝试从 json.decoder 导入 JSONDecodeError
from json.decoder import JSONDecodeError (I think its valid in python3 ? But why not working for me ?)
但它不起作用。只有以下工作:
from simplejson import JSONDecodeError
我是怎么做到的?
virtualenv venv --no-site-packages -p python3
pip install ipython
ipython
from json.decoder import JSONDecodeError
ImportError: cannot import name 'JSONDecodeError'
【问题讨论】:
-
您的文件是否命名为
json.py?请提供完整的追溯。 -
从 json 导入 JSONDecodeError
-
奇怪,这对我来说很好用。如果你尝试
from json import decoder; print(decoder.JSONDecodeError),你能看到会发生什么吗? -
在 [8] 中:打印(decoder.JSONDecodeError)------------------------------- -------------------------------------------- AttributeError Traceback(最近调用最后)
in () ----> 1 print(decoder.JSONDecodeError) AttributeError: 'module' object has no attribute 'JSONDecodeError' -
附上截图
标签: python python-3.x simplejson