0

I'm asking this question here and not on Stack Overflow because it appears to be MacOS specific. 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've tried a brew reinstall python3 to no avail.

  • Doesn't python3 come pre-installed? I certainly would never sully my hard drive with the language of the peasants on purpose and even then, would never use brew to do anything, yet I have python. The point here is I believe doing the brew install may be corrupting something. Uninstall python from brew, uninstall brew. Install the packages from python.org. – jnovack Oct 02 '20 at 14:28
  • Python3 via brew has not inherently been a problem for me-- and it's only necessary as a dependency for other brew-installed packages. I did corrupt the installation, however, and it turns out that, to your point, removing it completely allows built-in Python3 to be found. – Charney Kaye Oct 02 '20 at 15:05

2 Answers2

1

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

I cannot reproduce the errors on two Macs here, one running python 3.7.4 on Mojave; and one running 3.8.3 on Big Sur. I installed python directly from the packages on 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

Both say "Clang 6.0", if that's relevant.

It may be that your installation is corrupted, and you need to reinstall python3. If you're using HomeBrew or similar, then you may need to contact them for support.

benwiggy
  • 35,635