如何修复python3.7中的“没有名为vidcap的模块”

2024-05-15 07:36:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经安装好了照相机,效果很好。问题是,当我试图导入pygame时有一个ModuleNotFoundError。 (注:我是使用windows)

这是一个测试项目,我必须用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()

我每次尝试都会犯同样的错误。 错误消息是:

^{pr2}$

有什么建议吗?在


Tags: imageimportyoutubewindows错误教程pygamewin
2条回答

From the pygame documentaion

Pygame currently supports only Linux and v4l2 cameras.

EXPERIMENTAL!: This API may change or disappear in later pygame releases. If you use this, your code will very likely break with the next pygame release.

你在windows机器上吗?在

您可能想检查一下前面关于windows上的pygame的答案-python pygame.camera.init() NO vidcapture

你好像在用Windows。所以您需要为pygame.camera安装VideoCapture模块。一种简单的方法是从here(基于Python版本)获取预构建的wheel包,并使用pip安装它:

pip install VideoCapture‑0.9.5‑cp37‑cp37m‑win32.whl

这应该可以修复ModuleNotFoundError。在

相关问题 更多 >