[英]Import module error when running os.system virtualenv OpenCV
I'm trying to build a simple Python GUI around OpenCV so I can run facial recognition commands easily. 我正在尝试围绕OpenCV构建一个简单的Python GUI,以便可以轻松运行面部识别命令。 I'm using a Raspberry Pi thus Raspbian to do this
我正在使用Raspberry Pi,因此Raspbian可以做到这一点
It's a case of clicking a button and an os.system command executes allowing various functions to run. 这是单击按钮的情况,然后执行os.system命令以允许运行各种功能。
The issue is with trying to run these functions whilst in the Virtual Python Environment. 问题在于尝试在虚拟Python环境中运行这些功能。 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.
我需要进入virtualenv才能访问所需的模块,但是我了解每次运行os.system命令时都会创建一个新的shell,因此将我带离了虚拟环境。
I've looked into running my functions in one os.system however I still get the import module error. 我已经研究过在一个os.system中运行我的函数,但是仍然出现导入模块错误。
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. 这个想法是进入虚拟环境并执行另一个带有添加面部检测参数的python脚本。
NOTE: running this in the terminal works fine. 注意:在终端中运行此程序正常。
I would use the python from the virtualenv directly: 我会直接使用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")
To elaborate a script run using a python executable from a virtualenv will look for libraries relative to the python executable, ie inside the virtual environment. 要详细说明使用virtualenv中的python可执行文件运行的脚本,将查找相对于python可执行文件的库,即在虚拟环境中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.