MacOS BigSur环境下使用launchd自动化Selenium Python脚本遭遇Bootstrap failed:5错误求助
Hey there! That Bootstrap failed:5 error is almost certainly coming from how you're trying to handle the virtual environment and shell syntax in your ProgramArguments array. Let's break down the issues and fix them step by step.
The Core Problem
Launchd doesn't run commands through a shell by default. So when you put source, &&, or deactivate in your ProgramArguments array, it treats each of those as standalone executable files—which they aren't. source is a shell built-in, and && is a shell operator, so launchd can't execute them directly, hence the failure.
Solution 1: Skip Virtual Environment Activation (Simplest Fix)
You don't actually need to "activate" the virtual environment to run your script. Just call the Python executable directly from your virtual environment—it will automatically use the venv's dependencies without any activation steps.
Update your ProgramArguments array to this:
<key>ProgramArguments</key> <array> <string>/Users/Logan/PycharmProjects/Selenium/venv/bin/python3.6</string> <string>/Users/Logan/PycharmProjects/Selenium/ChowguleUpdateNotice.py</string> </array>
Solution 2: Use a Shell to Execute the Full Command
If you really want to use shell syntax (though it's unnecessary here), wrap the entire command in bash -c so launchd runs a shell that can interpret operators and built-ins. You can also skip the deactivate step—since the shell will exit right after the script finishes, the virtual environment "activation" will disappear automatically:
<key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>-c</string> <string>source /Users/Logan/PycharmProjects/Selenium/venv/bin/activate && python3.6 /Users/Logan/PycharmProjects/Selenium/ChowguleUpdateNotice.py</string> </array>
Extra Checks to Avoid Other Issues
- Ensure your log directory exists: Launchd will fail if it can't write to
stdout.logorstderr.log. Run this in Terminal to create the folder if it's missing:mkdir -p /Users/Logan/PycharmProjects/Selenium/logfiles - Add Selenium Headless Mode: When running via launchd, even in a GUI session, your browser might not launch properly without headless mode. Add this to your Python script's Selenium setup (example for Chrome):
from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument("--headless=new") driver = webdriver.Chrome(options=chrome_options) - Verify Permissions: Make sure all files (script, venv, log folder) are owned by your user
Loganand have read/write permissions for your account.
How to Test the Fixed Plist
- Unload the old plist if it's already loaded:
launchctl bootout gui/$(id -u Logan)/py.ChowguleNoticeUpdate - Load the updated plist:
launchctl bootstrap gui/$(id -u Logan) /path/to/your/plist/file.plist - Check if it's running:
launchctl list | grep py.ChowguleNoticeUpdate
If it still fails, check the stderr log at /Users/Logan/PycharmProjects/Selenium/logfiles/stderr.log—it should give you specific details about what's going wrong next.
内容的提问来源于stack exchange,提问作者Logan Botius

