【问题标题】:How to fix 'No module named vidcap' in python 3.7如何在 python 3.7 中修复“没有名为 vidcap 的模块”
【发布时间】:2019-11-13 01:15:16
【问题描述】:

我设置了摄像头,效果很好。问题是,当我尝试导入 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()

我每次尝试都会导致相同的错误。 错误信息是:

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'

有什么建议吗?

【问题讨论】:

  • 您好,请让我们看看完整的错误 - ModuleNotFoundError 表明您没有安装任何东西。
  • 这是最小的工作示例吗?换句话说,这是导致相同错误的绝对最小代码量吗?如果没有,请删除无关代码。
  • 编辑:我添加了错误信息并删除了一些代码
  • 赏金或回答任何人???
  • 你在用linux吗?

标签: python python-3.x pygame


【解决方案1】:

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 上。
  • 您是否尝试过链接答案中的解决方案?
  • 我做了,但我想要一个特定的版本。
  • 您在寻找哪个特定版本?
  • 最新版本
【解决方案2】:

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

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

这应该会修复ModuleNotFoundError

【讨论】:

  • 这里“cp37”中的“cp”代表cpython,默认情况下,pp是pypy。 “37”将是 python3.7 如果你在“C:”中有“Python39”,那么你想要“cp39”。
猜你喜欢
  • 1970-01-01
  • 2019-05-31
  • 1970-01-01
  • 2020-12-21
  • 2020-08-23
  • 2020-03-20
  • 2020-10-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多