fishjoe
fishjoe

Reputation: 49

Applescript call python failed

I have developed an AppleScript which needs to call a python file. i.e autorun.py the Autorun.py start with

import msoffcrypto
import pathlib
import os
....

Both the AppleScript and the python file run fine. I even tried to call autorun.py in the terminal and that also runs with no problem. But when the Applescript tried to call the python file:

set myPythonScript to POSIX path of "/Users/zhouyu/Library/Application Scripts/com.apple.mail/autounlock.py"

set myVal to do shell script "python" & space & myPythonScript's quoted form

display dialog myVal

It failed at the first line in the python code when Applescript tried to call it.

error "Traceback (most recent call last): File "/Users/zhouyu/Library/Application Scripts/com.apple.mail/autounlock.py", line 2, in import msoffcrypto ImportError: No module named msoffcrypto" number 1

Upvotes: 0

Views: 189

Answers (1)

has
has

Reputation: 176

Unlike Terminal.app, do shell script does not read your shell profile so make sure you give it the full path to your python interpreter, e.g.:

do shell script "/usr/local/bin/python3" & space & myPythonScript's quoted form

Upvotes: 1

Related Questions