I would like run a specific moment a python script to show with selenium the chromium browser on DISPLAY :0.0 .

00 11 * * * pi export DISPLAY=:0.0 && "/usr/bin/python2.7 /home/pi/Desktop/script.py"

Example python script:

# encoding=utf8
from selenium import webdriver

def main():
    options = webdriver.ChromeOptions()
    browser = webdriver.Chrome("/usr/bin/chromedriver",chrome_options=options)

if __name__ == "__main__":

Could you please help me?


First, the command with the quotes can't work:

"/usr/bin/python2.7 /home/pi/Desktop/script.py"

It might work without the quotes

/usr/bin/python2.7 /home/pi/Desktop/script.py

It depends on the X Server. It is likely that you will also need to set XAUTHORITY.

You can test this from the command line:

env -i DISPLAY=:0.0 /usr/bin/python2.7 /home/pi/Desktop/script.py

If this works, then your command should work if you remove the quote.

Otherwise try

env -i DISPLAY=:0.0 XAUTHORITY="$XAUTHORITY" /usr/bin/python2.7 /home/pi/Desktop/script.py

If this works, you need to set XAUTHORITY to the value of XAUTHORITY.

You may also need environment variables related to Python, like PYTHONSTARTUP, PYTHONHOME or PYTHONPATH.

  • At the end: 00 11 * * * env -i DISPLAY=:0.0 XAUTHORITY=/home/pi/.Xauthority /usr/bin/python2.7 /home/pi/Desktop/script.py It worked fine. Thanks – Francesco Jul 29 '19 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.