我已设置好相机,效果很好。事实是,当我尝试导入pygame时出现ModuleNotFoundError。
这是一个测试项目,我必须用pygame制作相机。我已经尝试了一些youtube教程,但将pygame弄得一团糟,但它总是会导致错误。
这是我到目前为止所拥有的:
import pygame.camera
pygame.camera.init()
camera = pygame.camera.list_cameras()[0]
pyg = pygame.camera.Camera(camera (640, 480), 'HSV')
--snip--
if pyg.query_image():
win.blit(pyg.get_image(surface=win), (0, 0))
pygame.quit()
每次尝试都导致相同的错误。 错误消息是:
Traceback (most recent call last):
File "C:\Users\roche\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygame\_camera_vidcapture.py", line 31, in init
import vidcap as vc
ModuleNotFoundError: No module named 'vidcap'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\roche\Documents\pygame_camera.py", line 5, in <module>
pygame.camera.init()
File "C:\Users\roche\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygame\camera.py", line 68, in init
_camera_vidcapture.init()
File "C:\Users\roche\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygame\_camera_vidcapture.py", line 33, in init
from VideoCapture import vidcap as vc
ModuleNotFoundError: No module named 'VideoCapture'
有什么建议吗?
答案 0 :(得分:3)
答案 1 :(得分:2)
似乎您正在使用Windows。因此,您需要为VideoCapture
安装pygame.camera
模块。一种简单的方法是从here(基于您的Python版本)中获取预构建的轮包,并使用pip
安装它:
pip install VideoCapture‑0.9.5‑cp37‑cp37m‑win32.whl
这应该解决ModuleNotFoundError
。