textract.process отлично работает при вызове через терминал, но не работает, когда тот же код запускается через launchctl - PullRequest
1 голос
/ 08 марта 2019

Резюме:

Я пытаюсь проанализировать PDF, используя textract.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

Вот путь, который (регистрируется sys.path в моем коде Python) запускается через терминал:

['/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']

Вот путь, когда (регистрируемый sys.path в моем коде Python до того, как я изменяю sys.path) запускается через launchctl:

/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>
...