通过终端调用时,textract.process可以正常工作,但通过launchctl启动相同的代码时,失败

时间:2019-03-08 11:06:04

标签: python macos launchd launchctl

摘要:

我正在尝试使用textract解析PDF。通过终端调用textract.process可以正常工作,但是通过launchctl

启动相同的代码时,失败
(Note : xxxxxxxxxx is my username crossed out)

错误消息:

命令pdf2txt.py /Users/xxxxxxxxxx/Downloads/a.pdf失败,因为可执行文件     pdf2txt.py未安装在您的系统上。使用textract之前,请确保安装了适当的依赖项:http://textract.readthedocs.org/en/latest/installation.html

$ which pdf2txt.py
/usr/local/bin/pdf2txt.py

$ ls -l /usr/local/bin/pdf2txt.py
-rwxrwxrwx  1 root  admin  4181 Mar  1 07:56 /usr/local/bin/pdf2txt.py

这里是通过终端启动时(由我的python代码中的sys.path记录)的路径:

['/Users/xxxxxxxxxx/Dropbox/Google Drive/My Software/Project/python', '/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg', '/Library/Python/2.7/site-packages/ofxclient-2.0.3-py2.7.egg', '/Library/Python/2.7/site-packages/ofxparse-0.16-py2.7.egg', '/Library/Python/2.7/site-packages/ofxhome-0.3.3-py2.7.egg', '/Library/Python/2.7/site-packages/lxml-3.8.0-py2.7-macosx-10.12-intel.egg', '/Library/Python/2.7/site-packages/keyring-10.4.0-py2.7.egg', '/Library/Python/2.7/site-packages/argparse-1.4.0-py2.7.egg', '/Library/Python/2.7/site-packages/six-1.10.0-py2.7.egg', '/Library/Python/2.7/site-packages/rsa-3.4.2-py2.7.egg', '/Library/Python/2.7/site-packages/httplib2-0.10.3-py2.7.egg', '/Library/Python/2.7/site-packages/gspread-0.6.2-py2.7.egg', '/Library/Python/2.7/site-packages/certifi-2017.7.27.1-py2.7.egg', '/Library/Python/2.7/site-packages/urllib3-1.22-py2.7.egg', '/Library/Python/2.7/site-packages/idna-2.6-py2.7.egg', '/Library/Python/2.7/site-packages/PyPDF2-1.26.0-py2.7.egg', '/Library/Python/2.7/site-packages/simplejson-3.11.1-py2.7-macosx-10.12-intel.egg', '/Library/Python/2.7/site-packages/PyGoogleVoice-0.5.2-py2.7.egg', '/Library/Python/2.7/site-packages/configparser-3.5.0-py2.7.egg', '/Library/Python/2.7/site-packages/twilio-6.7.0-py2.7.egg', '/Library/Python/2.7/site-packages/PyJWT-1.5.3-py2.7.egg', '/Library/Python/2.7/site-packages/fpdf-1.7.2-py2.7.egg', '/Library/Python/2.7/site-packages/pytesseract-0.1.7-py2.7.egg', '/Library/Python/2.7/site-packages/Pillow-4.3.0-py2.7-macosx-10.12-intel.egg', '/Library/Python/2.7/site-packages/olefile-0.44-py2.7.egg', '/Library/Python/2.7/site-packages', '/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/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', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

这里是通过launchctl启动时(在修改sys.path之前,在我的python代码中由sys.path记录)的路径:

/usr/bin:/bin:/usr/sbin:/sbin

这里是修改sys.path使其具有上面列出的所有内容后登录sys.path的路径:

['/Users/xxxxxxxxxx/Dropbox/Google Drive/My Software/Project/python', '/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg', '/Library/Python/2.7/site-packages/ofxclient-2.0.3-py2.7.egg', '/Library/Python/2.7/site-packages/ofxparse-0.16-py2.7.egg', '/Library/Python/2.7/site-packages/ofxhome-0.3.3-py2.7.egg', '/Library/Python/2.7/site-packages/lxml-3.8.0-py2.7-macosx-10.12-intel.egg', '/Library/Python/2.7/site-packages/keyring-10.4.0-py2.7.egg', '/Library/Python/2.7/site-packages/argparse-1.4.0-py2.7.egg', '/Library/Python/2.7/site-packages/six-1.10.0-py2.7.egg', '/Library/Python/2.7/site-packages/rsa-3.4.2-py2.7.egg', '/Library/Python/2.7/site-packages/httplib2-0.10.3-py2.7.egg', '/Library/Python/2.7/site-packages/gspread-0.6.2-py2.7.egg', '/Library/Python/2.7/site-packages/certifi-2017.7.27.1-py2.7.egg', '/Library/Python/2.7/site-packages/urllib3-1.22-py2.7.egg', '/Library/Python/2.7/site-packages/idna-2.6-py2.7.egg', '/Library/Python/2.7/site-packages/PyPDF2-1.26.0-py2.7.egg', '/Library/Python/2.7/site-packages/simplejson-3.11.1-py2.7-macosx-10.12-intel.egg', '/Library/Python/2.7/site-packages/PyGoogleVoice-0.5.2-py2.7.egg', '/Library/Python/2.7/site-packages/configparser-3.5.0-py2.7.egg', '/Library/Python/2.7/site-packages/twilio-6.7.0-py2.7.egg', '/Library/Python/2.7/site-packages/PyJWT-1.5.3-py2.7.egg', '/Library/Python/2.7/site-packages/fpdf-1.7.2-py2.7.egg', '/Library/Python/2.7/site-packages/pytesseract-0.1.7-py2.7.egg', '/Library/Python/2.7/site-packages/Pillow-4.3.0-py2.7-macosx-10.12-intel.egg', '/Library/Python/2.7/site-packages/olefile-0.44-py2.7.egg', '/Library/Python/2.7/site-packages', '/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/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', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Frameworks/Python.framework/Versions/2.7/bin', '/opt/local/bin', '/opt/local/sbin', '/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/opt/X11/bin', '/usr/local/git/bin']

这是.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>com.Project.restartProject
    </string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/python</string>
        <string>/Users/xxxxxxxxxx/Dropbox/Google Drive/My Software/Project/python/restartProject.py</string>
        <string>/usr/bin/python</string>
        <string>/usr/local/bin/pdf2txt.py</string>
    </array>
    <key>KeepAlive</key>
    <true/>
  </dict>
</plist>

0 个答案:

没有答案