Python 3 'json'모듈이 실제로 손상되었습니다.

Oct 02 2020

이 질문은 MacOS에 특정한 것처럼 보이기 때문에 Stack Overflow가 아니라 여기에 질문하고 있습니다. 거기에있는 많은 답변은 잘못된 "json.py"모듈을 검색하는 것을 가리 킵니다. 그러나 우리는 그런 나쁜 모듈이 임포트되고 있지 않다는 것을 다음에서 볼 수 있습니다.

Python 3 설치를 어떻게 "수정"합니까?

$ python3
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import json
>>> d = {'a' : 100, 'b' : 200}
>>> json.dumps(d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'json' has no attribute 'dumps'

>>> print(json.__file__)
None

위치는 다음과 같습니다.

$ which python3
/usr/local/bin/python3

나는 brew reinstall python3아무 소용이 없었습니다.

답변

benwiggy Oct 02 2020 at 21:14

두 Mac에서 오류를 재현 할 수 없습니다. 하나는 Mojave에서 python 3.7.4를 실행합니다. Big Sur에서 3.8.3을 실행하는 것. python.org의 패키지에서 직접 파이썬을 설치했습니다.

>>> json.dumps(d)
'{"a": 100, "b": 200}'
>>> print(json.__file__)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py

관련이있는 경우 둘 다 "Clang 6.0"이라고 말합니다.

설치가 손상되었을 수 있으며 python3을 다시 설치해야합니다. HomeBrew 또는 유사 제품을 사용하는 경우 지원을 위해 연락해야 할 수 있습니다.

CharneyKaye Oct 02 2020 at 21:24

나중에 "glib, graphviz 및 gts"를 다룰 것이라고 생각합니다.하지만 저에게 트릭은 Python 3의 brew 설치를 완전히 제거하는 것이 었습니다.

brew uninstall --ignore-dependencies python3

이제 모든 것이 정상으로 돌아 왔습니다.

$ python3
Python 3.7.3 (default, Apr 24 2020, 18:51:23) 
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> d = {'a' : 100, 'b' : 200}
>>> json.dumps(d)
'{"a": 100, "b": 200}'