Jeg er ved at tabe håret over det her problem
Jeg skal køre en python fil fra min webserver. Den virker fint i terminal, men når jeg skal køre den i PHP får jeg følgende fejl:
Array ( [0] => sh: sysctl: command not found [1] => Traceback (most recent call last): [2] => File "../server/search.py", line 5, in [3] => from pyimagesearch.colordescriptor import ColorDescriptor [4] => File "/Applications/MAMP/htdocs/toys/server/pyimagesearch/colordescriptor.py", line 3, in [5] => import cv2 [6] => File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cv2/__init__.py", line 6, in [7] => os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(__file__)) [8] => File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 40, in __getitem__ [9] => raise KeyError(key) [10] => KeyError: 'PATH' ) 1Min PHP kode:
-  $response = exec("python ../server/search.py 2>&1", $output, $return);
-          print_r($output);
-          echo $return;
Python kode:
-  #!/usr/bin/python
-  # python search.py --index index.csv --query queries/103100.png --result-path dataset
-  
-  # import the necessary packages
-  from pyimagesearch.colordescriptor import ColorDescriptor
-  from pyimagesearch.searcher import Searcher
-  import argparse
-  import cv2
-  import sys
-  
-  # construct the argument parser and parse the arguments
-  ap = argparse.ArgumentParser()
-  ap.add_argument("-i", "--index", required = True,
-      help = "Path to where the computed index will be stored")
-  ap.add_argument("-q", "--query", required = True,
-      help = "Path to the query image")
-  ap.add_argument("-r", "--result-path", required = True,
-      help = "Path to the result path")
-  args = vars(ap.parse_args())
-  
-  # initialize the image descriptor
-  cd = ColorDescriptor((8, 12, 3))
-  
-  # load the query image and describe it
-  query = cv2.imread(args["query"])
-  features = cd.describe(query)
-  
-  # perform the search
-  searcher = Searcher(args["index"])
-  results = searcher.search(features)
-  
-  # display the query
-  cv2.imshow("Query", query)
-  
-  # loop over the results
-  for (score, resultID) in results:
-      # load the result image and display it
-      print score
-      result = cv2.imread(args["result_path"] + "/" + resultID)
-      cv2.imshow("Result", result)
-      cv2.waitKey(0)
-  
-  
-  
-  sys.stdout.flush()