Jump to content

Making Python 2 Workflows work on macOS Monterey 12.3 and above

Recommended Posts

16 minutes ago, vitor said:
ln -s "${HOME}/.pyenv/versions/2.7.18/bin/python2.7" "${HOMEBREW_PREFIX}/bin/python"


I don't want to affect other code and projects on my machine which assume python is 3.x. In my case, I've just done a global replace within the workflow to call 2.7 directly (installed via pyenv but I didn't run the path update or do any symlinking; this works fine). This way my python setup for other projects is unaffected, but I can still run the workflow. Thanks!

Link to comment
2 minutes ago, iandol said:

I don't want to affect other code and projects on my machine which assume python is 3.x.


They shouldn’t assume it. While is is possible for python to link to python3, code which relies on Python 3 should call python3—that’s the official name of the binary.


11 minutes ago, iandol said:

This way


Naturally, you are free to edit these to your heart’s content and build your own setup as you desire, but the updated Workflows listed here are updated in the way they can remain closest to the originals.

Link to comment

I do have some other code that makes the python=python3 assumption, and in my case I have to flexibility to go this route. I totally agree for most users the Alfred instructions, along with your willingness to step in and your hard work in making this solution work is much appreciated, thank you!!!


Link to comment
On 2/4/2022 at 4:59 AM, vitor said:

With macOS Monterey 12.3, Apple removed the bundled Python 2 interpreter. That means older Workflows dependent on Python 2 will no longer work without modification.

You can reinstall Python 2, but some Workflows will still require a tweak to work. It’s simple enough to do if you know what to look for, but not everyone does. The Updated Third-Party Python 2 Workflows repository on GitHub is meant to close that gap.

Check the list of available Workflows. If the one you need isn’t present, ask for it there or as a reply on this thread. Be sure to include a link to the original.


Note this is only for Python 2 Workflows which break on Monterey 12.3 and above due to the Python 2 removal. If a Workflow stops working for any other reason, contact the author as usual.


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.

Link to comment
4 hours ago, vitor said:

Welcome @Larrikin,



I don’t understand what that means. Could you share the Workflow?


I ended up installing Python2 package on my Intel iMac. I have learned since that post that homebrew deals with the installation of python2 (or rather pyenv) differently depending on CPU architecture (Apple silicon vs Intel). I could not get python2 working with Alfred under macOS Intel architecture (whereas Apple silicon it worked exactly as expected).


So installing the official Python 2 package on my Intel iMac fixed the problem (basically it went back to what life was like before Apple removed Python 2 in 12.3) and it just works with Alfred. Not ideal as I don't know how to remove python2 later on when eventually my python2 workflows are upgraded to python3, but a problem for another day!

Link to comment
On 3/21/2022 at 11:33 PM, Larrikin said:

I don't know how to remove python2 later


In a terminal:


export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"
eval "$(brew shellenv)"
osascript -e "tell application \"Finder\" to delete (POSIX file \"${HOME}/.pyenv\")"
osascript -e "tell application \"Finder\" to delete (POSIX file \"${HOMEBREW_PREFIX}/bin/python\")"


Edited by vitor
Link to comment

I've followed the Python 2 and macOS Monterey instructions, updated to the new repo version of Browser Choice, but it still isn't working for me. If I use the workflow debug tool and attempt to paste a URL into Alfred, I get this output:


[15:36:05.628] Logging Started...
[15:36:06.705] Browser Choice[Script Filter] Queuing argument 's://www.alfredapp.com/help/kb/python-2-monterey/'
[15:36:06.718] Browser Choice[Script Filter] Script with argv 's://www.alfredapp.com/help/kb/python-2-monterey/' finished
[15:36:06.721] ERROR: Browser Choice[Script Filter] Code 127: /Users/my-user/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/8850345A-2270-4F6D-B339-8C297BC812DD: line 2: python: command not found


It can't find the python command after installing it…? Sorry, not a programmer, so I'm a little lost what to try next.


Thanks for all your work and help on this @vitor!

Link to comment
22 hours ago, vitor said:


In a terminal:


osascript -e "tell application \"Finder\" to delete (POSIX file \"${HOME}/.pyenv\")"
osascript -e "tell application \"Finder\" to delete (POSIX file \"${HOMEBREW_PREFIX}/bin/python\")"




I am referring to the python package I installed on my intel iMac from https://www.python.org/downloads/macos/. I don't know how to uninstall that when the time comes (as that was the only way I could get my intel iMac working with Alfred again) Doesn't what you've posted above only remove the pyenv (homebrew version)?  That's easy to remove as you can even just type pyenv uninstall 2.7.18 The pyenv solution did not work for me at all on the Intel Mac (on my Apple silicon mac it worked just fine so I have different solutions in place depending on CPU architecture).



Edited by Larrikin
Link to comment
4 hours ago, Travis Schmeisser said:

It can't find the python command after installing it…?


What’s the output of ls -la "${HOMEBREW_PREFIX}/bin/python"?


1 hour ago, Larrikin said:

That's easy to remove as you can even just type pyenv uninstall 2.7.18


No, that just uninstalls the package itself, it does not remove the changes made by it.

Link to comment

Concerning the "Password Generator" workflow - I got it working by reinstalling python2 (as suggested) and installing the workflow version from your repo. It is launching correctly, thank you.


However, when trying to save a generated password to the clipboard I get an error:


Traceback (most recent call last):
  File "/Users/mich/Dropbox/AlfredSync/Alfred.alfredpreferences/workflows/user.workflow.27383A38-5810-4F40-8FC8-D902948966E3/workflow/workflow.py", line 2073, in run
  File "pwgen.py", line 577, in main
    return app.run()
  File "pwgen.py", line 190, in run
    return getattr(self, meth)()
  File "pwgen.py", line 471, in do_copy
    import pasteboard as pb
  File "/Users/mich/Dropbox/AlfredSync/Alfred.alfredpreferences/workflows/user.workflow.27383A38-5810-4F40-8FC8-D902948966E3/pasteboard.py", line 22, in <module>
    from AppKit import NSPasteboard
ImportError: No module named AppKit



I already  tried doing ./pip install AppKit from /.pyenv/versions/2.7.18/bin - but I still get the error.


Any ideas?



Link to comment
4 hours ago, michbsd said:

Concerning the "Password Generator" workflow


The error means that particular action requires the Objective-C bridge. There’s a very small subset of Python 2 Workflows who do. At the moment it’s not viable to support those because the required Python packages fail (for me?) to build under Apple Silicon. If you’re on Intel, you may be able to do so ("${HOME}/.pyenv/versions/2.7.18/bin/python2.7" -m pip install PACKAGE_NAME) but the build failure makes it impossible for me to support it.


1 hour ago, eshmootie said:

but as of the update the following workflow is broken for me


Welcome @eshmootie,


That Workflow doesn’t use Python, so whatever is broken is something else. @Acidham has a Workflow you may wish to try.


27 minutes ago, Travis Schmeisser said:

The output is "ls: /bin/python: No such file or directory"


Try again with:

eval "$(brew shellenv)"
ls -la "${HOMEBREW_PREFIX}/bin/python"


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...