How to fix 'No module named vidcap' in python 3.7

我怕爱的太早我们不能终老 提交于 2020-01-02 04:54:30

问题


I have camera set up, which works fine. The thing is, there is an ModuleNotFoundError when I am trying to import pygame. (Note:I am using windows)

This is a test project, and I have to make a camera out of pygame. I've tried some youtube tutorials and I messed with pygame but it always causes an Error.

This is what I have so far:

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()

I resulted in the same error every time I tried. The Error message is:

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'

Any Advice?


回答1:


It seems that you are using Windows. So you need to install VideoCapture module for the pygame.camera. An easy way is to grab the prebuilt wheel package from here (based on your Python version) and install it with pip:

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

This should fix the ModuleNotFoundError.




回答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.

Are you on a windows machine?

You might want to check this previous answer about pygame on windows - python pygame.camera.init() NO vidcapture



来源:https://stackoverflow.com/questions/56851629/how-to-fix-no-module-named-vidcap-in-python-3-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!