0

I want to use Python 3 on my Mac High Sierra system. I installed with brew using the following ...

localhost:tmp davea$ brew reinstall python3
==> Reinstalling python 
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.6_1.high_sierra.bottle.tar.gz
Already downloaded: /Users/davea/Library/Caches/Homebrew/downloads/3d94ccb6613548e55aed20c7ee59f0e0b7fb045a5d9c8885aa3504ea31f8ab0e--python-3.7.6_1.high_sierra.bottle.tar.gz
==> Pouring python-3.7.6_1.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/pyt
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/pyt
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/pyt
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
  /usr/local/Cellar/python/3.7.6_1: 3,977 files, 60.8MB

However, when I try and run a simple command, I'm getting a "ModuleNotFoundError: No module named 'encodings'" error. I'm just trying to parse some JSON. What else do I need to do to get Python installed properly?

localhost:tmp davea$ echo $json
{"id": "abc", "name": "dave"}
localhost:tmp davea$ echo $json | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj["id"])'
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fff9f066380 (most recent call first):
Abort trap: 6
localhost:tmp davea$ echo $json | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["id"])'
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fff9f066380 (most recent call first):
Abort trap: 6:
Dave
  • 15,639
  • 133
  • 442
  • 830
  • Does this answer your question? [Fatal Python error: initfsencoding: unable to load the file system codec](https://stackoverflow.com/questions/54087049/fatal-python-error-initfsencoding-unable-to-load-the-file-system-codec) – bfontaine Mar 05 '20 at 16:55
  • Hi, Do you mean the accepted answer? THey are referring to a Windows installation (I'm on Mac). I tried reinstalling (output is in my question). Let me know if this is what you were referring to. – Dave Mar 05 '20 at 17:23
  • Check whether the issue is with brewed python - remove brewed one and use the official installer from python.org/downloads, if the error is not reproducible, file an issue at https://github.com/Homebrew/homebrew-core. – hoefling Mar 05 '20 at 18:05
  • BTW, `echo $json` is inherently buggy. Always quote: `echo "$json"` -- otherwise, if your json contains, say, `{"title": " * BEST EVER FOOBAR * "}`, the `*`s in that string will be replaced with lists of filenames in the current directory. – Charles Duffy Mar 05 '20 at 18:30
  • (Can't reproduce the problem myself, but I use Nix as my package manager rather than Homebrew). – Charles Duffy Mar 05 '20 at 18:30
  • Hi @CharlesDuffy, Thanks for the advice. Tried ' echo "$json" | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["id"])'', but got the same error. – Dave Mar 05 '20 at 21:23
  • That's normal, because that's a problem that *completely* breaks your Python install, it's not specific to JSON. If your Python install is completely broken, it's, well, *completely* broken. It's not expected to work, at all, for anything. – Charles Duffy Mar 05 '20 at 22:38
  • ...so asking this as a JSON problem instead of a "why doesn't my Python interpreter work?" problem is a bit silly. – Charles Duffy Mar 05 '20 at 22:39

0 Answers0