python - 刚刚在 Mac 上安装了 Python,但出现“ModuleNotFoundError: No module named 'encodings'”错误
问题描述
我想在我的 Mac High Sierra 系统上使用 Python 3。我使用以下方法安装了 brew ...
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
但是,当我尝试运行一个简单的命令时,我收到“ModuleNotFoundError: No module named 'encodings'”错误。我只是想解析一些 JSON。我还需要做什么才能正确安装 Python?
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:
解决方案
推荐阅读
- r - xyplot添加数据框线#上面的点
- angular - 如何以这种格式将文档上传到 AWS S3 domain_name/my_bucket_name/my_folder_name
- python - 单词列表 A 与单词列表 b 和单词列表 C 的所有组合,同时保持所述列出单词的顺序
- vba - 表单提交后如何从 IE 获取对象的更新值?
- javascript - 未知参数:Webpack 2.7.0 中的主题
- python - 使用 Python 模块将 PDF 转换为 XML/json
- python - 如何设置事件侦听器以检测 iframe 中使用 Selenium 和 Python 流式传输内容的变化
- rust - 为什么这个不相关的箱子会破坏我的项目?
- javascript - 在php中提交或页面刷新后如何保持复选框的选中状态?
- php - Estes Web 服务 API