我是新手,我制作了一个简单的Python脚本,可以播放视频
import os
import sys
import pygame
from pygame.locals import *
from subprocess import Popen
movies = "revolving.mp4"
playingmovie = ["omxplayer","-b","/home/pi/Videos/"+movies]
omxc = Popen(playingmovie, stdout=subprocess.PIPE, preexec_fn=os.setsid)
哪个会发出以下错误:
File "test2.py", line 9, in <module>
omxc = Popen(playingmovie, stdout=subprocess.PIPE, preexec_fn=os.setsid)
NameError: name 'subprocess' is not defined
我试图对此做一些研究,但没有找到解决我问题的答案。在上述研究中,我发现我应该运行命令
sudo find / | grep subprocess
返回哪个
/usr/lib/python2.7/subprocess.pyc
/usr/lib/python2.7/subprocess.py
/usr/lib/python3.5/__pycache__/subprocess.cpython-35.pyc
/usr/lib/python3.5/subprocess.py
/usr/lib/python3.5/asyncio/__pycache__/base_subprocess.cpython-35.pyc
/usr/lib/python3.5/asyncio/__pycache__/subprocess.cpython-35.pyc
/usr/lib/python3.5/asyncio/base_subprocess.py
/usr/lib/python3.5/asyncio/subprocess.py
/usr/lib/pypy/lib-python/2.7/__pycache__/subprocess.pypy-41.pyc
/usr/lib/pypy/lib-python/2.7/subprocess.py
/usr/lib/pypy/lib_pypy/__pycache__/_subprocess.pypy-41.pyc
/usr/lib/pypy/lib_pypy/_subprocess.py
我该如何解决?
答案 0 :(得分:2)
您正尝试使用subprocess
,但您仅从子流程包中导入了一个类。
您可以导入整个subprocess
并像这样使用它:
import os
import sys
import pygame
from pygame.locals import *
import subprocess
movies = "revolving.mp4"
playingmovie = ["omxplayer","-b","/home/pi/Videos/"+movies]
omxc = subprocess.Popen(playingmovie, stdout=subprocess.PIPE, preexec_fn=os.setsid)