py2exe上的网络摄像头无法正常工作

时间:2017-08-26 17:14:46

标签: python windows pygame webcam py2exe

您好我编写了一个使用网络摄像头的程序,但是当我通过py2exe将其设为 exe 时 因为这个错误而崩溃。

error:

这是我的代码

import pygame.camera
import pygame.image
import sys
pygame.camera.init()
cameras = pygame.camera.list_cameras()


webcam = pygame.camera.Camera(cameras[0])

webcam.start()

 # grab first frame
img = webcam.get_image()

WIDTH = img.get_width()
HEIGHT = img.get_height()

screen = pygame.display.set_mode( ( WIDTH, HEIGHT ) )
pygame.display.set_caption("pyGame Camera View")

while True :
    for e in pygame.event.get() :
        if e.type == pygame.QUIT :
            sys.exit()

     # draw frame
    screen.blit(img, (0,0))
    pygame.display.flip()
     # grab next frame    
    img = webcam.get_image()

谢谢:)

2 个答案:

答案 0 :(得分:0)

不确定这是否可行(我无法在我的计算机上运行python代码),但您是否尝试过pyinstaller而不是Py2Exe(http://pyinstaller.org)?

答案 1 :(得分:0)

嘿伙计们,我终于可以用cx_freeze创建一个可执行文件了 这可以用于相机 解决方案是您应该将vidcapture.pyd复制到包含程序的文件中

this picture is my file that have vidcapture.pyd