I was using Catalina OS with MySQL Workbench for Mac, which worked fine for old iMac of mine. But when I recently bought a new Mac with Big Sur OS and installed MySQL Workbench, it gave me the follow import error:
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):
I knew that this was due to system path improperly configured as my python version is 3.8. So I added a path to the system path in bash_profile. See below:
export PYTHONPATH=~/Library/Python/3.8/lib/python/site-packages:$PYTHONPATH
export PATH=/usr/bin:$PATH
The resulting sys.path in python shell gave me this:
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']
I sourced the file and restarted the computer. However, I get the same error message when I try to run MySQL Workbench. I found the following website that explains where to update the system environment for MySQL Workbench, but it only shows examples for Windows and Linux OSs. How do I add a path to the system path for MySQL Workbench for Mac? Much appreciated.
I found the following solution: https://bugs.mysql.com/bug.php?id=102364
MySQLWorkbench need Python3.7 Framework in /Library/Frameworks/
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
Or you can just create a symlink to the entire file (thx to @Phillip1982)
sudo ln -s /usr/local/Cellar/python@3.7/3.7.10_1/Frameworks/Python.framework /Library/Frameworks/Python.framework