Many thanks for posting this. It worked perfectly for my MacBook Pro M1 Max. It puts the path /opt/homebrew/bin/python/ and that is is the dropdown box in Alfred as expected in Workflows. I then modify my script to run from the same path and works perfectly.
On my iMac Intel, the path remains /usr/bin/python
typing /usr/bin/python --version shows Python 2.7.18. It's also in the path so I can just type python --version.
So if I select from the dropdown in Alfred with /usr/bin/python and then point my script with /usr/bin/python it does not work.
I followed the instructions exactly as described here https://www.alfredapp.com/help/kb/python-2-monterey/ on both machines. Why I got a different results on the MacBook Pro M1 Max from my iMac Intel I don't know. I specifically and obviously mentioning one is running Apple silicon and the other is running intel on the basis there could be something in that.
Lost as to where to go from here, so any help would be greatly appreciated.