sendgrid를 통해 링크가 포함 된 전자 메일을 보내는 python 스크립트를로드하는 launchd를 사용하여 일일 예약 된 plist 작업을 작성하려고합니다.Launchd plist 작업 파이썬 sys.path 오류
python dailyemail.py
와 명령 줄에서 이메일 작품을 보낼 내 파이썬 스크립트 내가로드하고 지정된 시간에 실행 내 PLIST 작업을 시작하면
import os, requests, bs4, sendgrid
from sendgrid.helpers.mail import *
url = 'https://apod.nasa.gov/apod/astropix.html'
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("xxx")
to_email = Email("xxx")
subject = "Astronomy Picture of the Day"
content = Content("text/plain", 'https://apod.nasa.gov/apod/astropix.html')
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
(아래 참조)하지만,없는 때문에 실패 requests, bs4 and sendgrid
모듈을 가져올 수 있습니다. sys.path
출력 로깅에서 내 시스템이 launchd를 통해 작업을 실행할 때 대 명령 행에서 두 가지 미묘하게 다른 버전의 Python을로드하는 것 같습니다 (최종 및 plist 작업의 출력 참조).
- 어떻게이 격차를 해결 않습니다
나는이 개 질문이? 또한 이 파일 경로가 다른 이유를 이해하는 데 관심이 있습니까?
- 로드 할 수있는 또 다른 방법은 파이썬 모듈을 작동시키기 위해 plist 작업에 참조할까요?
고마워요!
시스템 : OSX 엘 캐피 10.11.3
PLIST 작업
<?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>
<!-- The label should be the same as the filename without the extension -->
<string>com.alexanderhandy.nasa</string>
<!-- Specify how to run your program here -->
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python</string>
<string>/Users/alexanderhandy/Documents/Programming/Scripts/dailyemail.py</string>
</array>
<!-- Run every dat -->
<key>StandardErrorPath</key>
<string>/tmp/ahnasa.err</string>
<key>StandardOutPath</key>
<string>/tmp/ahnasa.out</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>34</integer>
</dict>
</dict>
</plist>
오류 로그를 확인 여기에 다른 사람이 그래서
*Command line python sys.path*
/Users/alexanderhandy/Documents/Programming/Scripts/usr/local/lib/python2.7/site-packages/setuptools-17.0-py2.7.egg/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python27.zip/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/usr/local/lib/python2.7/site-packages/Library/Python/2.7/site-packages
*plist task python sys.path*
/Users/alexanderhandy/Documents/Programming/Scripts/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/Library/Python/2.7/site-packages
감사합니다. @montmons - 올바른 길로 나를 안내했습니다. 솔루션은 내 plist에있는''' /usr/local/Cellar/python/2.7.10/bin/python2.7 ''' –
AlexHandy1
에 homebrew가 설치된 python bin 디렉토리에 직접 연결되는 것을 끝내었다. 그것이 듣고있어 기쁘다. – Montmons