问题描述
我使用 Catalina OS 和 MysqL Workbench for Mac,它在我的旧 iMac 上运行良好。但是当我最近买了一台带有 Big Sur OS 的新 Mac 并安装了 MysqL Workbench 时,它给了我以下导入错误:
Fatal Python error: initfsencoding: unable to load the file system codec,sys.path = ['/Applications/MysqLWorkbench.app/Contents/Resources/libraries','/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip','/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7','/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload']
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000000011ac12e00 (most recent call first):
我知道这是由于系统路径配置不当,因为我的 python 版本是 3.8。所以我在bash_profile中添加了系统路径的路径。见下文:
export PYTHONPATH=~/Library/Python/3.8/lib/python/site-packages:$PYTHONPATH
export PATH=/usr/bin:$PATH
python shell 中的结果 sys.path 给了我这个:
Python 3.8.2 (default,Nov 4 2020,21:23:28)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help","copyright","credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['','/Library/Developer/CommandLinetools/Library/Frameworks/python3.framework/Versions/3.8/lib/python38.zip','/Library/Developer/CommandLinetools/Library/Frameworks/python3.framework/Versions/3.8/lib/python3.8','/Library/Developer/CommandLinetools/Library/Frameworks/python3.framework/Versions/3.8/lib/python3.8/lib-dynload','/Users/phillipkim/Library/Python/3.8/lib/python/site-packages','/Library/Developer/CommandLinetools/Library/Frameworks/python3.framework/Versions/3.8/lib/python3.8/site-packages']
我找到了文件并重新启动了计算机。但是,当我尝试运行 MysqL Workbench 时,我收到了相同的错误消息。我发现以下 website 解释了在哪里更新 MysqL Workbench 的系统环境,但它只显示了 Windows 和 Linux 操作系统的示例。如何为 MysqL Workbench for Mac 添加系统路径的路径?非常感谢。
解决方法
我找到了以下解决方案:https://bugs.mysql.com/bug.php?id=102364
MySQLWorkbench 需要 /Library/Frameworks/
中的 Python3.7 框架
- 运行
brew install python@3.7
- 然后,运行
sudo cp -r /usr/local/Cellar/python@3.7/3.7.9_3/Frameworks/Python.framework /Library/Frameworks/Python.framework
- 最后,打开 MySQLWorkbench,它就可以工作了。
或者你可以创建一个指向整个文件的符号链接(感谢@Phillip1982)
sudo ln -s /usr/local/Cellar/python@3.7/3.7.10_1/Frameworks/Python.framework /Library/Frameworks/Python.framework