我在 Python 中使用 mss 库来截取屏幕截图并将其保存在当前路径上。它使用 PyCharm 在我的 Mac 上完美运行。但是当我尝试在 Ubuntu 16 上运行相同的东西时,我得到一个错误,即使我完全按照文档所说的那样做:
>>> from mss import mss
>>> with mss() as sct:
... sct.shot()
但我收到此错误,如何解决?
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/mss/linux.py", line 132, in __init__
display = os.environ['DISPLAY'].encode('utf-8')
File "/usr/lib/python3.5/os.py", line 725, in __getitem__
raise KeyError(key) from None
KeyError: 'DISPLAY'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/mss/factory.py", line 34, in mss
return MSS(**kwargs)
File "/usr/local/lib/python3.5/dist-packages/mss/linux.py", line 134, in __init__
raise ScreenShotError('$DISPLAY not set.', locals())
mss.exception.ScreenShotError: ('$DISPLAY not set.', {'display': None, 'self': <mss.linux.MSS object at 0x7f06ce881d30>})