There is a python file

#!/usr/bin/ python from pyvirtualdisplay import Display from selenium import webdriver def main(): with Display(visible=False, size=(1200, 1500)): firefox_dir = "/usr/bin/selenium/webdriver/firefox" ff_profile = webdriver.FirefoxProfile(profile_directory=firefox_dir) browser = webdriver.Firefox(ff_profile) browser.get("http://www.python.org") print browser.title browser.close() if __name__ == "__main__":main() 

There is a task in crown * * * * * export DISPLAY =: 0 && / usr / bin / python /var/www/test/test.py> /tmp/listener_new.log 2> & 1

Beats mistake

 Traceback (most recent call last): File "/var/www/test/test.py", line 14, in <module> if __name__ == "__main__":main() File "/var/www/test/test.py", line 9, in main browser = webdriver.Firefox(ff_profile) File "/home/dev/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__ self.service.start() File "/home/dev/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

Tell me, good people, what could be the error? From the terminal, the script starts and runs.

  • "'geckodriver' executable needs to be in PATH." - in what directory geckodriver lies? ( shutil.which('geckodriver') ) Is it in os.environ['PATH'] ? (when starting from cron) - jfs
  • @jfs, And what is this os.environ ['PATH']? How to perform a check, do not tell me? - Irina Kochenova
  • print(os.environ['PATH']) add to your script when it starts from cron (if you don’t know what $ PATH is the environment variable, ask a separate question). Compare with the python -с "import shutil; print(shutil.which('geckodriver'))" directory shown by the command in the terminal. - jfs
  • @jfs, thanks, moved the geckodriver to / usr / bin and it all worked. :) - Irina Kochenova

1 answer 1

Check out sys.path for yourself and set the necessary $ PATH variables when running in crown. Try it in your terminal

 which geckodriver 

Like me

 which chromedriver /usr/local/bin/chromedriver 

This path must be put in cron.