Reputation: 25
I'm trying to build a simple Python GUI around OpenCV so I can run facial recognition commands easily. I'm using a Raspberry Pi thus Raspbian to do this
It's a case of clicking a button and an os.system command executes allowing various functions to run.
The issue is with trying to run these functions whilst in the Virtual Python Environment. I need to be inside the virtualenv to gain access to the required modules however I understand every time a os.system command is ran, a new shell is created therefore taking me out the virtual environment.
I've looked into running my functions in one os.system however I still get the import module error.
Something that i assumed would take a few mins to build is taking me days.
Any help on this would be amazing.
Thank you.
Here is my current code:
from tkinter import *
import os
from tkinter import messagebox
# creating tkinter window
root = Tk()
root.geometry('500x500')
root.title("Student Attendnace System")
def stillImage():
os.system("/home/pi/.virtualenvs/cv/bin/activate & python recognize_faces_image.py ---encodings encodings.pickle --detection-method hog --image examples/example_01.jpg")
btn3 = Button(root, text = 'Detect Faces From Image', command = stillImage)
btn3.grid(column=1, row=2)
mainloop()
The idea is to enter the virtual environment and execute another python script with added facial detection arguments.
NOTE: running this in the terminal works fine.
Upvotes: 0
Views: 219
Reputation: 1605
I would use the python from the virtualenv directly:
os.system("/home/pi/.virtualenvs/cv/bin/python recognize_faces_image.py ---encodings encodings.pickle --detection-method hog --image examples/example_01.jpg")
To elaborate a script run using a python executable from a virtualenv will look for libraries relative to the python executable, i.e. inside the virtual environment.
Upvotes: 2