3

これを使用して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サーバーを使用しています。どうすればこれを機能させることができますか?

4

0 に答える 0