1

I am trying to run a Python Script for Image Detection Via a php page and to catch and display the output generated by py script.

Here is my python script GITHUB LINK

I am running the python script using this code :

$command = escapeshellcmd('sudo python Main.py');
$output = shell_exec($command);
echo $output;

This is producing this error :

Traceback (most recent call last):
  File "Main.py", line 3, in <module>
    import cv2
ImportError: No module named cv2

****But the same script works fine when executed independently with terminal. I have used anaconda for installation of Opencv****

Thanks in advance :)

4
  • Are you typing the same command while executing the script independently in terminal? Commented Jun 25, 2017 at 9:56
  • Yes I am using the same. Commented Jun 25, 2017 at 9:58
  • And do you have a virtual environment for it? Commented Jun 25, 2017 at 9:59
  • No I am not using Virtual environment. Commented Jun 25, 2017 at 10:01

2 Answers 2

5

Anaconda creates separate environment so you need to start your script using python copy from that enviroment

$command = escapeshellcmd('sudo /home/path_to_anacondad_env/python Main.py');
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I was totally unaware of that
1

The same thing happened to me, I installed openCV with pip install but when I ran it from php I couldn't find it, but I found that I only have to install it globally with this command: sudo apt-get install python3-opencv I restarted Apache and that worked for me

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.