运行 os.system virtualenv OpenCV 时导入模块错误

Import module error when running os.system virtualenv OpenCV

我正在尝试围绕 OpenCV 构建一个简单的 Python GUI,以便我可以轻松地 运行 面部识别命令。我正在使用 Raspberry Pi 因此 Raspbian 来做这个

这是单击按钮和执行 os.system 命令的情况,允许各种功能 运行。

问题在于在虚拟 Python 环境中尝试 运行 这些功能。我需要进入 virtualenv 才能访问所需的模块,但是我知道每次 os.system 命令是 运行 时,都会创建一个新的 shell,因此将我带出虚拟环境。

我已经 运行 研究了我的函数 os.system 但是我仍然遇到导入模块错误。

我认为需要几分钟才能构建的东西却花了我几天时间。

这方面的任何帮助都会很棒。

谢谢。

这是我当前的代码:

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() 

想法是进入虚拟环境并执行另一个 python 添加了面部检测参数的脚本。

注意:运行在终端中使用它可以正常工作。

我会直接使用 virtualenv 中的 python:

os.system("/home/pi/.virtualenvs/cv/bin/python recognize_faces_image.py ---encodings encodings.pickle --detection-method hog --image examples/example_01.jpg")

要使用来自 virtualenv 的 python 可执行文件来详细说明脚本 运行 将查找与 python 可执行文件相关的库,即在虚拟环境中。