How to resolve “chromedriver executable needs to be in PATH” error when running Selenium Chrome using virtualenv within PyDev?

梦想的初衷 提交于 2019-12-05 01:46:19

Not sure if this is the best thing to do, but I have found something that seems to work: I have added to my interpreter the already available variable named PATH, and I have edited that variable's value to include the relative path to my project's virtual environment's bin directory (ie, the directory where I have the chromedriver executable file saved).

More precisely:

  1. Window menu in Eclipse > Preferences > PyDev on the left > Interpreters > Python Interpreters.

  2. Selected the interpreter that I had created earlier for my project (as descibed in the question above)

  3. Switched from Libaries to Environment in the bottom half of the Preferences window

  4. Clicked on the Select... button on the right.

    A list of Environment Variable appeared.

  5. Scrolled down through the list and found one named PATH. Selected it and click on the OK button.

    It and its value (/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games) appeared in the otherwise empty list.

  6. I selected it and clicked on Edit...

    Its name and value became editable.

  7. To the right-hand end of the value I added :env/bin (ie, the relative path from the directory holding my script to my project's virtual environment's bin directory).

  8. Clicked OK to get back to the Preferences window > Apply in the Preferences window > OK to close the Preferences window.

  9. Ran the program from within Eclipse (selected the script file > Run menu > Run As > Python Run).

A Chrome (well, Chromium - this is Debian) window opened just as had been happening when I was running my program from the command prompt.

Great.

If all attempts to put chromedriver in your PATH fail, you can also hand the executable path to webdriver.Chrome() like so:

chromedriver_loc = '/path/to/chromedriver'
driver = webdriver.Chrome(executable_path=chromedriver_loc)

This was my eventual solution when trying to run chromedriver from a virtualenv.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!