py2exe在PIL ImageStat.Stat中抛出异常:参数2必须是ImagingCore,而不是ImagingCore

0 投票
1 回答
788 浏览
提问于 2025-04-16 01:55

我正在尝试使用py2exe把一个Python程序变成.exe文件,但当我运行这个.exe时,出现了一个日志文件,里面有

Exception in thread Thread-1:
Traceback (most recent call last):
  File "threading.pyc", line 532, in __bootstrap_inner
  File "threading.pyc", line 484, in run
  File "webcam.py", line 66, in loop
  File "ImageStat.pyc", line 50, in __init__
  File "PIL\Image.pyc", line 990, in histogram
TypeError: argument 2 must be ImagingCore, not ImagingCore

这里有一些代码:

#webcam.py
          cam = VideoCapture.Device();
          def getImage():
            return cam.getImage();
    ...
        camshot = grayscale(getImage());
        lightCoords = [];
        level = camshot.getextrema()[1]-leniency;
        for p in camshot.getdata():
          if p>=level:
            lightCoords.append(255);
          else:
            lightCoords.append(0);
        maskIm = new("L",res);
        maskIm.putdata(lightCoords);
    ...

    64      colorcamshot = getImage();
    65      camshot = grayscale(colorcamshot);
    66      brightness = ImageStat.Stat(camshot,maskIm).sum[0]/divVal;

1 个回答

0

在你启动任何工作线程之前,试着在主线程中先导入PIL库。看起来同一个类被导入了两次,这导致类型比较出现了一些奇怪的问题。

撰写回答