Just installed Python on Mac, but getting “ModuleNotFoundError: No module named 'encodings'” error

梦想与她 提交于 2020-03-25 16:56:58

问题


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:

来源:https://stackoverflow.com/questions/60550018/just-installed-python-on-mac-but-getting-modulenotfounderror-no-module-named

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!