You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

What we will happen with Python 2 in Automotor?

Since Python will go away in future version of macOS, what will happen with quick actions using this language in Automator?


I am using a Python 2 script in Automator and I would like to use more of them in the future but in Python 3. In the menu for script execution, we can choose Python, Perl, Ruby and one of the many shell command line languages. But we can't choose in languages installed outside macOS. This is not very flexible but I really like this ability to create macros assigned to keyboard shortcuts. Ideally, it would be great to be able to choose any executable file.


How do you think I can manage the transition to a macOS not having this possibility?

Posted on Feb 6, 2022 7:44 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 6, 2022 8:54 AM

In macOS 12.3, Python v2.7.18 that is in macOS 12.2, will be removed from the operating system, and any Automator workflow that references /usr/bin/python will abort. I would recommend not upgrading to macOS 12.3 until you have provided the following workaround and edited your Automator workflows accordingly.


Expect the reference to /usr/bin/python to disappear from the Automator or Shortcuts Run Shell Script actions. This is surmountable using a HERE invocation of Python, which I will share further on.


Python 2.7.18 has been deprecated by Python.org and no further work will be done on it. This version (as per post date) is still available from python.org as a macOS 64-bit installer. You could install this, and then install the last universal2 release of python 3.* (currently 3.10.2). Both of these will install directly into the /Library/Frameworks/Python.framework, and will be linked to /usr/local/bin as python and python3. You will need to modify your PATH to include library bin paths for each of these distributions.


I recommend that you migrate your Python 2.7.* code to Python 3 as quickly as possible. In either case, you would use a Run Shell Script action with shell set to your default shell (e.g. bash, or zsh). Then you would run your new Python executable as a HERE script:



You would use /usr/local/bin/python instead of /usr/local/bin/python3 initially. You can see above how I pass arguments into the Python HERE script and you would process those with:


for f in sys.argv[1:]:


5 replies
Question marked as Top-ranking reply

Feb 6, 2022 8:54 AM in response to JeanMeslier

In macOS 12.3, Python v2.7.18 that is in macOS 12.2, will be removed from the operating system, and any Automator workflow that references /usr/bin/python will abort. I would recommend not upgrading to macOS 12.3 until you have provided the following workaround and edited your Automator workflows accordingly.


Expect the reference to /usr/bin/python to disappear from the Automator or Shortcuts Run Shell Script actions. This is surmountable using a HERE invocation of Python, which I will share further on.


Python 2.7.18 has been deprecated by Python.org and no further work will be done on it. This version (as per post date) is still available from python.org as a macOS 64-bit installer. You could install this, and then install the last universal2 release of python 3.* (currently 3.10.2). Both of these will install directly into the /Library/Frameworks/Python.framework, and will be linked to /usr/local/bin as python and python3. You will need to modify your PATH to include library bin paths for each of these distributions.


I recommend that you migrate your Python 2.7.* code to Python 3 as quickly as possible. In either case, you would use a Run Shell Script action with shell set to your default shell (e.g. bash, or zsh). Then you would run your new Python executable as a HERE script:



You would use /usr/local/bin/python instead of /usr/local/bin/python3 initially. You can see above how I pass arguments into the Python HERE script and you would process those with:


for f in sys.argv[1:]:


Feb 6, 2022 8:19 AM in response to JeanMeslier

JeanMeslier wrote:

Since Python will go away in future version of macOS, what will happen with quick actions using this language in Automator?

They'll break.

we can't choose in languages installed outside macOS.

Why not? I suspect that if you install Python 3 then Automator will be happy to use it. Even if that doesn't work, it still supports all the other shell scripts. It would be trivially easy to just run /bin/sh and execute whatever interpreter you want.

Feb 6, 2022 10:02 AM in response to VikingOSX

In continuance, my PATH for using Python 3.10.1 is:


export PATH="$HOME/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/opt/homebrew/bin:${PATH}"


You would likely need to add an additional Python library path as above, but for 2.7. I use the python.org installers, and homebrew for other things. As I am using an M1 Mac, and unrelated to python, I use its specific /opt/homebrew/bin PATH location for this architecture.


Once you have the python.org 2.7.18 and 3.* installations complete and PATH adjustment, then python scripts run from the Terminal command line can use this first line in the script:


#!/usr/bin/env python
#!/usr/bin/env python3


This is not true for Automator/Shortcuts Run Shell Scripts though.


Python.org installations due not natively see the current Apple Python scripting bridge to Objective-C frameworks. Even if one does add the optional pyobjc package to the Python.org installations (3.6 or later) it is not clear if macOS 12.3 breaks this access with Apple's removal of Python.



Feb 6, 2022 11:08 AM in response to JeanMeslier

Apple has already thought about it and will be removing Pages v2.7.18 in macOS 12.3. From their perpective, they have given us 2.5 years (Catalina ➝ Monterey) to migrate Pages v2.7.* code to Python 3. This will still burn those with complicated Python production code who either didn't know this was coming, or procrastinated…

What we will happen with Python 2 in Automotor?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.