All Python scripts stopped working: path changed in all projects after macOS Monterey 12.6 update

Viewed 500

After updating macOS Monterey today to 12.6 all my Python projects/scripts have stopped working.

Checking the symlink of a Python binary in one of my project's venv, I see the original to be:
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9
which is not in path list!? Installed with the macOS update today?

it seems that all the symlinks to Python in the virtual environments of all of my VS Code projects now point to the binary above, and none of the projects work anymore, all with ModuleNotFoundError.

How can I get all my projects to work again?

Background/details:

.bash_profile:

# Setting PATH for Python 3.8
PATH="/Library/Python/3.8/bin:${PATH}"
export PATH

.zprofile:

PATH="/Library/Python3.9/bin:${PATH}"
export PATH

eval "$(/opt/homebrew/bin/brew shellenv)"

.zshrc:

export PATH=$PATH:/Users/xxxx/Library/Python/3.8/bin

The scripts run with venv activated ((venv)...), confirmed with which python which accurately returns the path of Python in venv (though symlinked to the weird path).

When trying to (re)install those libraries, with venv still active, they get installed in root Python with following warning:

WARNING: The scripts f2py, f2py3 and f2py3.9 are installed in '/Users/xxxxxx/Library/Python/3.9/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

I'm using /bin/zsh when run in VS Code. Same from stand-alone terminal window. I shared Bash above as listed in paths.

tried:

echo $PATH

returns (edited for readability):

/opt/homebrew/bin:
/opt/homebrew/sbin:
/Library/Python3.9/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/MacGPG2/bin:
/Library/Apple/usr/bin:
/Users/xxxx/Library/Python/3.8/bin

notes:

  • the last path (/Users/..) seems to be the one used by Bash but not Zsh/VS Code/. This was working as is before the update though.
  • need to add missing path: /Users/xxxx/Library/Python/3.9/bin

checking paths one by one:

  • /opt/homebrew/bin: no Python binary in folder
  • /opt/homebrew/sbin: no Python binary in folder
  • /Library/Python3.9/bin: folder Python3.9 does not exist
  • /usr/local/bin: /usr/local/bin/python found +++
  • /usr/bin: /usr/bin/python3 found +++
  • /bin: no Python binary in folder
  • /usr/sbin: no Python binary in folder
  • /sbin: no Python binary in folder
  • /usr/local/MacGPG2/bin: no Python binary in folder
  • /Library/Apple/usr/bin: no Python binary in folder
  • /Users/xxxx/Library/Python/3.8/bin: no Python binary in folder
  • not returned with echo $PATH / need to be added: /Users/xxxx/Library/Python/3.9/bin also no Python binary in folder
  • not listed but symlinked now in all projects: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9
2 Answers

I had the same issue in VS Code running notebooks. I uninstalled and reinstalled the Jupyter extension. Then when attempting to run a notebook for the first time again, there is a prompt to install jupyter notebook. Once done, all the notebooks are running fine again for all the environments I am using.

I'm experiencing this, as well. Some people at my company have had success by reinstalling Xcode or running the following:

xcodebuild -runFirstLaunch

But it has not worked for me.

Venv seems completely broken and can't properly create new environments except when I use Python 3.10 like this:

python3.10 -m venv venv

But even then the modules in my scripts won't connect to any of the packages I install in the lib/python3.10/site-packages directory. I'm out of ideas.

Related