我正在尝试在我的树莓派上运行 PyVirtualDisplay 来打开一个网页。但是,当我运行它时,会引发错误。
错误如下:
Traceback (most recent call last):
File "test.py", line 4, in <module>
from pyvirtualdisplay import Display
File "/usr/local/lib/python2.7/dist-packages/pyvirtualdisplay/__init__.py", line 4, in <module>
from pyvirtualdisplay.display import Display
File "/usr/local/lib/python2.7/dist-packages/pyvirtualdisplay/display.py", line 26
backend: Optional[str] = None,
^
SyntaxError: invalid syntax
我正在运行的代码如下:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1600, 1200))
display.start()
driver = webdriver.Chrome()
driver.get('https://colab.research.google.com/drive/1pqGSjrP3SujtxNwoB_AgVqM0c5DI8R4q')
driver.ActionChains(driver).key_down(Keys.CONTROL).send_keys(Keys.ENTER).perform()
我在我的树莓派 3 B+ 上运行它,它的最新固件。我已经使用 pip 安装了 pyvirtualdisplay,并且还安装了 xvfb。
我不确定为什么会发生错误,但这似乎是由于“display.py”文件中的错误。
“display.py”文件的相关部分如下(有错误的行在第3行):
def __init__(
self,
backend: Optional[str] = None,
visible: bool = False,
size: Tuple[int, int] = (1024, 768),
color_depth: int = 24,
bgcolor: str = "black",
use_xauth: bool = False,
# check_startup=False,
retries: int = 10,
extra_args: List[str] = [],
manage_global_env: bool = True,
**kwargs
):
self._color_depth = color_depth
self._size = size
self._bgcolor = bgcolor
self._visible = visible
self._backend = backend
if not self._backend:
if self._visible:
self._backend = "xephyr"
else:
self._backend = "xvfb"
cls = _class_map.get(self._backend)
if not cls:
raise ValueError("unknown backend: %s" % self._backend)
self._obj = cls(
size=size,
color_depth=color_depth,
bgcolor=bgcolor,
retries=retries,
use_xauth=use_xauth,
# check_startup=check_startup,
extra_args=extra_args,
manage_global_env=manage_global_env,
**kwargs
)
我不知道该怎么做,任何帮助将不胜感激。谢谢你!