Help with Automator running a shell script

I've set up a workflow in Automator to get operator input and select a folder from various locations depending on the input. I tested the capture of variables with print statements in a very basic python script and it executes as expected.

Now I'm trying to expand that python script to run the actual steps I need. I've tested the python script in IDLE and it works but when I try to run it from the Run Shell Script in Automator I get an error on some of the import statements. The python libraries are all installed (it runs in IDLE) but Automator doesn't like something that I'm doing (or not doing).

It fails on the import zxingcpp -- just for fun I've reordered the import statements and whenever it tries one of the last three it fails. All libraries are installed at

Location: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages


I'm running iMac 27" Late 2015 Monterey v 12.6.4

Python 3.10.4

pip 23.0.1

zxing-cpp 2.0.0


I've been using AppleScript up until now with a lot of help from this community. AppleScript has been great but when moving or copying hundreds of images it often times out. This program not only will move hundreds of images but also is reading QR Codes to determine where to move them. I'm just getting started with python and so far each program has run in Automator, not this one. Any help is greatly appreciated.


/usr/bin/python3 <<'EOF' - "${@}"

import sys
import os
import csv
import shutil
import zxingcpp
import cv2
from PIL import Image

iMac 27″, macOS 12.6

Posted on Apr 18, 2023 04:55 AM

Reply
Question marked as Top-ranking reply

Posted on Apr 18, 2023 05:47 AM

I install Python3 using the Python.org installers and my python3 is in /usr/local/bin/python3, which would have access to any third-party installed packages in the corresponding framework location that you mention.


You are referencing /usr/bin/python3 which could only be there by installing Xcode or the Command Line Tools for Xcode, and clearly cannot see your installed site packages which are installed elsewhere. Apple does not install idle3 in Xcode or the Command Line Tools.


Finally, you may not need the python3 HERE <<< expression if the Run Shell Script Shell: selector now shows a path to /usr/local/bin/python3 as does mine. If it does, you can omit the python invocation in the Run Shell Script and collect your passed arguments from sys.argv[1:].


Here is the Run Shell Script Shell: selector menu from my macOS 12.6.5 Automator. Note that I reinstalled Python 2.7.18, and Python 3.11.2.




Similar questions

3 replies
Question marked as Top-ranking reply

Apr 18, 2023 05:47 AM in response to JB001

I install Python3 using the Python.org installers and my python3 is in /usr/local/bin/python3, which would have access to any third-party installed packages in the corresponding framework location that you mention.


You are referencing /usr/bin/python3 which could only be there by installing Xcode or the Command Line Tools for Xcode, and clearly cannot see your installed site packages which are installed elsewhere. Apple does not install idle3 in Xcode or the Command Line Tools.


Finally, you may not need the python3 HERE <<< expression if the Run Shell Script Shell: selector now shows a path to /usr/local/bin/python3 as does mine. If it does, you can omit the python invocation in the Run Shell Script and collect your passed arguments from sys.argv[1:].


Here is the Run Shell Script Shell: selector menu from my macOS 12.6.5 Automator. Note that I reinstalled Python 2.7.18, and Python 3.11.2.




Apr 18, 2023 06:21 AM in response to VikingOSX

You are a genius! I don't know how you know all this but I really am thankful. My Run Shell Script Shell:selector looks identical to yours. Yes, I did install Xcode and I installed Python3 from the Python.org installers.

I used the /user/local/bin/python3 and it now finds the installed packages. I'm back in business.

Thanks again

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Help with Automator running a shell script

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