Subprocess error in python
from subprocess import Popen,PIPE
from Tkinter import *
root=Tk()
calc=Frame(root)
calc.grid()
root.title("Calculator")
bt=Button(calc,text="3")
bt.grid()
process=subprocess.Popen(['python','imacap.py'],stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
In given code I created GUI using tkinter in python. While displaying GUI app, I want to run camera capturing app at the same time so after googling it I found solution of using subprocess.Popen. So I created imacap.py and used in it. But now I am facing error as Traceback (most recent call last):
File "/home/mukund/testa.py", line 9, in process=subprocess.Popen(['python','imacap.py'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE) NameError: name 'subprocess' is not defined
你应该改变你的导入到“导入子流程”
You are importing Popen
and PIPE
from subprocess
. Now you can access Popen
or PIPE
directly, no need of subprocess
as prefix.
If you want to use subprocess
as prefix then change your import.
import subprocess
Then subprocess.Popen
will work.
下一篇: python中的子进程错误