如何在Linux中将Chromedriver添加到PATH? [英] How to add Chromedriver to PATH in linux?

查看:1143
本文介绍了如何在Linux中将Chromedriver添加到PATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Python脚本中将Selenium与Chrome结合使用.

Trying to use Selenium with Chrome in a python script.

我收到以下错误:

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

我知道chromedriver可执行文件的位置. 如何将其添加到PATH?

I know the location of the chromedriver executable. How do I add it to the PATH?

谢谢

推荐答案

您可以在脚本中指定chrome驱动程序的绝对路径,如下所示:

You can specify the absolute path to your chrome driver in your script as such:

from selenium import webdriver
driver = webdriver.Chrome(executable_path='/path/to/driver/chromedriver')

或者您可以在PATH系统变量中将网络驱动器的路径添加为:

Or you can add the path to your webdriver in the PATH system variable as so:

export PATH=$PATH:/path/to/driver/chrome-driver

您可以将以上行添加到您的/home/<user>/.profile文件中,以使其永久保存.

You may add the above line to your /home/<user>/.profile file to make it permanent.

在运行Python 2.7.14的Ubuntu 17.10上测试

Tested on Ubuntu 17.10 running Python 2.7.14

希望这会有所帮助!

这篇关于如何在Linux中将Chromedriver添加到PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆