I have setup OpenCV 3.0 with python3.4 binding on ubuntu 14.04. I run OpenCV using virtualenv. So, everytime I have to run the workon cv
command.
Now I want to run a python script that uses OpenCV library from PHP using the exec
command.
exec("workon cv");
exec("python3 hough_circles.py")
This is the error :
sh: 1: workon: not found
Traceback (most recent call last):
File "hough_circles.py", line 1, in <module>
import cv2
ImportError: No module named 'cv2'
Two issues...
1. PATH to workon
The error message is telling you it doesn't know where workon
is, so you better tell it the full path to where it is so exec()
can find it, e.g.:
exec("/usr/local/bin/workon cv");
The /usr/local/bin
above is just an example, if you want to know where it is on your system, run:
which workon
and use the output.
2. Subprocesses are independent
Even when you have got that set correctly, the process that executes workon
then exits and you start a fresh, shiny new one - in which you have not run workon
. So, you better do both things in the same process like this:
exec("/usr/local/bin/workon cv && /path/to/python3 hough_circles.py");