“Pillow was built without XCB support”

。_饼干妹妹 提交于 2021-01-27 17:39:28

问题


I'm working on a program that uses ImageGrab in Pillow. I am getting the error mentioned in the title. I notice in the documentation that it says the generic pip install Pillow doesn't come with libxcb. I tried installing libxcb with pip install libxcb, but it apparently doesn't exist as that. I tried looking around on Google for it, but none of it helped.

If anybody could point me to the specific library that I need to install and commands to run, I'd appreciate it!

I should mention that the python that I'm running is the Windows Store v3.8. I am trying to keep a minimal amount on my SSD and didn't want a large overhead of stuff I won't use.


回答1:


I finally figured it out. What was going on is that I was trying to use grab(x, y, w, h) without the bbox=(x, y, w, h) parameter. Over my two day journey, I did not find a single helpful thing on the Internet. I thought the whole time it was not working because of a missing package or some Linux/Windows conversion dependency.

I hope this helps anybody that comes across this very simple, but agonizing error.

Here is exactly what I was doing:

def grab(x, y, w, h):
    screen = np.array(ImageGrab.grab(x, y, w, h)) # Throws XCB error
    ...
    return screen

Here is the correct code for a Windows platform:

def grab(x, y, w, h):
    screen = np.array(ImageGrab.grab(bbox=(x, y, w, h))) # Throws no errors
    # screen = np.array(ImageGrab.grab()) # Alternative that grabs full screen
    ...
    return screen



回答2:


I had the same error while I was using the Ubuntu terminal for Windows 10. Figured that was the issue because it sometimes has weird errors when its executing more os orientated stuff.

If anyone else has this error and they're using the Ubuntu terminal, try running it with the Windows CMD.




回答3:


you can use 'pyscreenshot' python package that works just like PIL.ImageGrab

import pyscreenshot as ImageGrab
bbox=(0, 0, 1366, 768)
screenshot = ImageGrab.grab()

https://pypi.org/project/pyscreenshot/



来源:https://stackoverflow.com/questions/61537007/pillow-was-built-without-xcb-support

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