Importing cv2 through VB for web app
I have a functional python script that performs facial recognition using dlib and opencv.
My problem: as soon as I run the python script through VB as a web app, I receive an error "System.Exception: 1".
I have isolated the problem; the error only occurs when I include the line "import cv2" in the python script being executed.
Once again, this only happens when I run the python script through VB. When I run the python script through Spyder or command prompt it runs perfectly. I have successfully installed OpenCV in the the environment that VB is using, and I have reinstalled the module in an attempt to solve the issue, but to no avail.
VB code running Python script with image path as an argument:
Dim Processtask As New System.Diagnostics.Process()
Processtask.StartInfo.FileName = "cmd.exe"
Processtask.StartInfo.Arguments = "/c python " + path.ToString + " " + ImageURL.ToString
Processtask.StartInfo.UseShellExecute = False
Processtask.StartInfo.RedirectStandardOutput = True
Processtask.StartInfo.RedirectStandardError = True
Processtask.StartInfo.CreateNoWindow = True
Processtask.Start()
Processtask.WaitForExit()
output = Processtask.StandardOutput.ReadToEnd()
Python code snippet receiving image path:
import sys
import cv2
if __name__ == "__main__":
im = str(sys.argv[1])
print(im)
I have run out of ideas as to what could cause this problem. Any advice on this would be greatly appreciated.
EDIT
I managed to find the full error message which reads as follows:
System.Exception: System.IO.StreamReader
System.InvalidOperationException: Process has exited, so the requested information is not available.
at System.Diagnostics.Process.EnsureState(State state) at System.Diagnostics.Process.get_ProcessName()
at System.Diagnostics.Process.ToString()
though VB is entirely off-topic here, please add your code to the question.
and one of the problems might be: while your python ide properly sets environment vars, before running it, your VB script might inherit some other env, thus not finding the path to the site-libs and such.
Thanks for the response. It is strange that my .py script run through VB is able to import all the other modules used in the program (quite a long list of them). Only cv2 produces an error.
do you have more than 1 python on your box ?
there must also be a way to reach the printed error msg
The server only has the Anaconda distribution of Python installed. I've updated the post with the full error message.