Python 运行os.system virtualenv OpenCV时导入模块错误
我正试图围绕OpenCV构建一个简单的Python GUI,以便可以轻松地运行面部识别命令。我用树莓皮做这个 这是一种单击按钮并执行os.system命令的情况,允许运行各种功能 问题在于在虚拟Python环境中尝试运行这些函数。我需要在virtualenv中才能访问所需的模块,但我知道每次运行os.system命令时,都会创建一个新的shell,从而使我脱离虚拟环境 我已经研究过在一个操作系统中运行我的函数,但是仍然会出现导入模块错误 一些我认为需要几分钟才能完成的东西,现在却需要几天的时间 这方面的任何帮助都将是惊人的 多谢各位 这是我目前的代码:Python 运行os.system virtualenv OpenCV时导入模块错误,python,opencv,raspberry-pi,virtualenv,Python,Opencv,Raspberry Pi,Virtualenv,我正试图围绕OpenCV构建一个简单的Python GUI,以便可以轻松地运行面部识别命令。我用树莓皮做这个 这是一种单击按钮并执行os.system命令的情况,允许运行各种功能 问题在于在虚拟Python环境中尝试运行这些函数。我需要在virtualenv中才能访问所需的模块,但我知道每次运行os.system命令时,都会创建一个新的shell,从而使我脱离虚拟环境 我已经研究过在一个操作系统中运行我的函数,但是仍然会出现导入模块错误 一些我认为需要几分钟才能完成的东西,现在却需要几天的时间
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可执行文件相关的库,即在虚拟环境中。我将直接使用来自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可执行文件相关的库,即在虚拟环境中。很高兴它帮助了您:)很高兴它帮助了您:)