1

I am trying to run PyVirtualDisplay on my raspberry pi to open up a webpage. However, when I run it, an error is thrown.

The error is as follows:

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

The code that I am running is as follows:

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()

I am running this on my raspberry pi 3 B+, on its latest firmware. I have installed pyvirtualdisplay using pip, and also have installed xvfb.

I am not sure why the error is occurring, but it seems to be due to an error in the "display.py" file.

The relevant parts of the "display.py" file is below(the line with the error is in line 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
         )

I do not know what to do, any help would be much appreciated. Thank You!

pigeen
  • 13
  • 4
  • You are running a very, very, very old version of Python that does not support those "type hints". You should try using "python3" instead of "python" to run your script. – Tim Roberts Jun 30 '21 at 22:28
  • `driver.ActionChains(driver).key_down(Keys.CONTROL).send_keys(Keys.ENTER).perform()` - this looks incorrect - instead it should be - `ActionChains(driver).key_down(Keys.CONTROL).send_keys(Keys.ENTER).perform()` – cruisepandey Jul 01 '21 at 04:35
  • @TimRoberts thank you, didn't realize I was running in 2.7, it now works by switching to 3.7(python3)! – pigeen Jul 02 '21 at 00:35
  • @cruisepandey thank you for noticing that, must have added the driver by accident, it now works without errors! – pigeen Jul 02 '21 at 00:37

0 Answers0