Вызов скрипта python из php без импорта необходимых модулей

Я вызываю скрипт Python, используя в PHP, используя этот

$text = shell_exec("python import pdf2txt; parser_py/cv_parser.py -i '".$filepath."' 2>&1");

Обратите внимание, что $ filepath был объявлен ранее, и это не проблема.

Это скрипт на питоне

import textract, os, sys, getopt

def main(argv):
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
sys.exit()
elif opt in ("-i"):
print textract.process(arg)

if __name__ == "__main__":
main(sys.argv[1:])

Textract импортирует другие модули, и они терпят неудачу, когда я бегу через php, но работает нормально, когда я бегу через терминал. Это ошибка ниже

string(1635) "Traceback (most recent call last):
File "parser_py/cv_parser.py", line 39, in
main(sys.argv[1:])
File "parser_py/cv_parser.py", line 32, in main
print textract.process(arg)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/textract-1.4.0-py2.7.egg/textract/parsers/__init__.py", line 57, in process
return parser.process(filename, encoding, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/textract-1.4.0-py2.7.egg/textract/parsers/utils.py", line 44, in process
byte_string = self.extract(filename, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/textract-1.4.0-py2.7.egg/textract/parsers/pdf_parser.py", line 25, in extract
return self.extract_pdfminer(filename, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/textract-1.4.0-py2.7.egg/textract/parsers/pdf_parser.py", line 49, in extract_pdfminer
stdout, _ = self.run('pdf2txt.py "%(filename)s"' % locals())
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/textract-1.4.0-py2.7.egg/textract/parsers/utils.py", line 92, in run
command, pipe.returncode, stdout, stderr,
textract.exceptions.ShellError: The command `pdf2txt.py "/Applications/AMPPS/www/insidify_cv_training/files/2musa_bello.pdf"` failed because the executable
`pdf2txt.py` is not installed on your system. Please make
sure the appropriate dependencies are installed before using
textract:

http://textract.readthedocs.org/en/latest/installation.html

"

Я использую сервер AMPPS на Mac. Как мне сделать эту работу, пожалуйста?

2

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector