我正在使用这个在 php 中调用 python 脚本
$text = shell_exec("python import pdf2txt; parser_py/cv_parser.py -i '".$filepath."' 2>&1");
请注意,$filepath 已在前面声明,这不是问题。
这是python脚本
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:])
文本导入其他模块,当我通过 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
"
我在 mac 上使用 AMPPS 服务器。请问我该怎么做?