MacOS Python 3.7.7 internal json module is corrupted; how to fix?

420 Views Asked by At

I'm running MacOS Catalina 10.15.7, and opened up a regular Terminal session. Yes, I run tmux in my shell, but this hasn't been a problem ever, until suddenly in the middle of my workday yesterday.

The only event I can think of that correlates in time to the problem starting is a moment using my IDE (IntelliJ IDEA, primarily a Java project with some ops tooling written in Python) and clumsily selected "install" when it claimed those modules were not found-- the correct move would have been simply to point the IDE to the Python 3.7 interpreter, a pretty standard part of checking a project out on a machine.

Many answers over there point to searching for a bad "json.py" module however we can see from the following that no such bad module is being imported.

How do I "fix" the Python 3 installation?

$ 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

Here's where it is located:

$ which python3
/usr/local/bin/python3

I believe this confirms my memory that it's been installed via brew:

$ brew uninstall python3
Error: Refusing to uninstall /usr/local/Cellar/python/3.7.7
because it is required by glib, graphviz and gts, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies python3

However, I've tried a brew reinstall python3 to no avail.

1

There are 1 best solutions below

0
On

Well I suppose I will deal with "glib, graphviz and gts" later, but what did the trick for me was to entirely remove the brew installation of Python 3:

brew uninstall --ignore-dependencies python3

And now things are back to normal:

$ 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}'