Bug #102364 MySQL Workbench 8.0.23 unable to start due to wrong system python paths
Submitted: 25 Jan 2021 10:02 Modified: 15 Apr 2021 10:32
Reporter: Georgi Sotirov Email Updates:
Status: Duplicate Impact on me:
Category:MySQL Workbench Severity:S3 (Non-critical)
Version: OS:MacOS (Big Sur 11.1)
Assigned to: CPU Architecture:x86

[25 Jan 2021 10:02] Georgi Sotirov
I'm not able to start the recently released MySQL Workbench 8.0.23 on MacOS Big Sur 11.1 while the previous version worked just fine. Trying to run the application on the Terminal gives me the following:

% ~/Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench
Fatal Python error: initfsencoding: unable to load the file system codec, sys.path = ['/Users/georgi/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 0x0000000108036e00 (most recent call first):
zsh: abort      ~/Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench

So it's clearly a matter of wrong Python paths, because system's Python is installed in /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7 and when I start the application with the following command it works just fine.

PYTHONPATH=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7 ~/Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench

I guess the problem is due to the following change from the release notes (see https://dev.mysql.com/doc/relnotes/workbench/en/news-8-0-23.html#workbench-8-0-23-feature):

MySQL Workbench now uses Python 3 for functionality such as migration, scripting shell, administrative tasks, and its SQL IDE. MySQL Workbench also ensures that installations on macOS (10.15 and later) have a valid version of Python available rather than relying on an operating system to provide the necessary scripting language.

Apparently, MySQL still relies on some Python modules to be provided by the system, because I do not find encodings into MySQLWorkbench.app package. Why is MySQL Workbench using the wrong paths to system Python? How could I make it use the correct paths apart from setting PYTHONPATH environment variable?

How to repeat:
1. Download MySQL Workbench 8.0.23 for Mac OS from https://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-workbench-community-8.0.23-macos-x...
2. Install to user's Applications folder.
3. Double click the MySQLWorkbench.app package in Finder.

Suggested fix:
Use the correct paths to system's Python.
[25 Jan 2021 12:17] MySQL Verification Team
Hello Georgi Sotirov,

Thank you for the bug report.
Imho this is duplicate of Bug #102284, please see Bug #102284.

Ashwini Patil
[25 Jan 2021 13:14] Georgi Sotirov
It's good to know that I'm not the only one experiencing this problem looking at the other duplicates of 102284 (i.e. currently 102285, 102305, 102314 and 102355). However in none of these bugs I see a solution (or workaround). When can we (the affected) expect a solution? I hope we won't have to wait until the next 8.0 releases in April...

P.S. I find a way to work around the problem by running the following before trying to start the application:

launchctl getenv PYTHONPATH /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7

It works at least for me.
[4 Feb 2021 8:35] Li Json
This is my temporary solution:
MySQLWorkbench need Python3.7 Framework in /Library/Frameworks/
1. brew install python@3.7
2. sudo cp -r /usr/local/Cellar/python@3.7/3.7.9_3/Frameworks/Python.framework /Library/Frameworks/Python.framework
3. open MySQLWorkbench, it's work
[17 Feb 2021 16:22] JOHN YEARY
I agree for the most part with Li Json, but I used a symbolic link instead of copying all the files over.

1. brew install python@3.7
2.  sudo ln -s /usr/local/Cellar/python@3.7/3.7.9_3/Frameworks/Python.framework /Library/Frameworks/Python.framework
3. Launch MySQLWorkbench.app or run from command line  "/Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench" --verbose
[15 Apr 2021 10:32] Georgi Sotirov
That's of course launchctl setenv and not launchctl getenv as I wrote in my comment from 25 Jan 13:14, which I'm not able to edit.

Also I choose this as workaround, because I'm not able to use brew.
[7 Apr 2023 12:24] Stefan Heisl
One possible solution to this bug is to update the paths used by MySQL Workbench to point to the correct location of the system Python. This can be done by modifying the MySQL Workbench startup script.

Here's how you can do it:

Open the MySQL Workbench application package deal with the aid of right-clicking on it and choosing "Show Package Contents".

Edit the script with a text editor.

Locate the line that sets the PYTHONPATH environment variable and update it to point to the correct location of the system Python. For example, if the system Python is located at "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7", the line should look like this:

export PYTHONPATH="/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7:${PYTHONPATH}" https://retailtechinnovationhub.com/home/2023/4/5/revolutionising-application-modernisatio...

Save the script and exit the text editor.