Search code examples
pythonmacos-mojave

Run Python script on launchctl - error 127


So im trying to run a script through LaunchAgents on osx and i keep getting the Service exited with abnormal code: 127 error.

When i run the scrip in the terminal , everything works (its just a test script to open a browser tab). I already validated the .plist file, but here it is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>local.restart</string>
        <key>Program</key>
        <string>/Users/flp/PythonScripts/run.py</string>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key> 
        <integer>60</integer>
    </dict>
</plist>

And here is the script:

#! /usr/bin/env python3
import webbrowser

a_website = "https://www.abola.pt"

# Open url in a new window of the default browser, if possible
webbrowser.open_new(a_website)

This is the log from launchctl:

com.apple.xpc.launchd[1] (local.restart[3080]): Service exited with abnormal code: 127

Am i doing something wrong?


Solution

  • The problem was in the shebang. The compiler path was not correct, fixed it and it works as suposed.