To set the environment of a specific job you should use the EnvironmentVariables
key in the job definition itself:
<?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>com.example.app</string>
<key>Program</key>
<string>/path/to/your/script</string>
<key>EnvironmentVariables</key>
<dict>
<key>PYTHONPATH</key>
<string>/your/python/path</string>
</dict>
</dict>
</plist>
You may define default environment variables for launchd(8)
services by editing /etc/launchd.conf
for daemons or /etc/launchd-user.conf
for agents. The latter one works but is not documented. The currently documented (but unsupported) per-user config file is $HOME/.launchd.conf
.
These config files contain a list of launchctl(1)
subcommands. The one you want is:
setenv PYTHONPATH /your/python/path
Update: /etc/launchd.conf
is not supported in Mac OS X 10.10 and higher. On these systems you'll have to define environment variables on a per-job-basis.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…