Python selenium - chromedriver 可执行文件需要在 PATH 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40555930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
selenium - chromedriver executable needs to be in PATH
提问by Sebastian Nielsen
Error message:
错误信息:
'chromedriver' executable needs to be in PATH
'chromedriver' 可执行文件需要在 PATH 中
I was trying to code a script using selenium in pycharm, however the error above occured. I have already linked my selenium to pycharm as seen here (fresh and up to date).
我试图在 pycharm 中使用 selenium 编写脚本,但是发生了上面的错误。我已经将我的 selenium 链接到 pycharm,如下所示(新鲜且最新)。
I am new to selenium, isn't chromedriver in the folder "selenium." If it isn't, where can I find it and add it to the path?
我是硒的新手,不是“硒”文件夹中的 chromedriver。如果不是,我在哪里可以找到它并将其添加到路径中?
By the way, I tried typing "chromedriver" in cmd, however, it wasn't recognized as an internal or external command.
顺便说一句,我尝试在 cmd 中键入“chromedriver”,但是,它未被识别为内部或外部命令。
error shown below:
错误显示如下:
Traceback (most recent call last):
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
PermissionError: [WinError 5] Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/sebastian/PycharmProjects/web/bot.py", line 10, in <module>
browser = webdriver.Chrome("C:/Users/sebastian/desktop/selenium-3.0.1")
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'selenium-3.0.1' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x01EDEAF0>>
Traceback (most recent call last):
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
回答by Maximilian Peters
You can download ChromeDriver here: https://sites.google.com/a/chromium.org/chromedriver/downloads
您可以在此处下载 ChromeDriver:https: //sites.google.com/a/chromium.org/chromedriver/downloads
Then you have multiple options:
那么你有多种选择:
- add it to your system
path
- put it in the same directory as your python script
specify the location directly via
executable_path
driver = webdriver.Chrome(executable_path='C:/path/to/chromedriver.exe')
- 将其添加到您的系统中
path
- 把它放在与你的python脚本相同的目录中
直接通过指定位置
executable_path
driver = webdriver.Chrome(executable_path='C:/path/to/chromedriver.exe')
回答by thebadguy
Another way is download and unzip chromedriver and put 'chromedriver.exe' in C:\Python27\Scripts and then you need not to provide the path of driver, just
另一种方法是下载并解压chromedriver并将'chromedriver.exe'放在C:\Python27\Scripts中,然后你不需要提供驱动程序的路径,只需
driver= webdriver.Chrome()
will work
将工作
回答by BUGATTI AJAY
Try this :
尝试这个 :
pip install webdriver-manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
回答by Erich Purpur
Do not include the '.exe' in your file path.
不要在文件路径中包含“.exe”。
For example:
例如:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='path/to/folder/chromedriver')
回答by minTwin
An answer from 2020. The following code solves this. A lot of people new to selenium seem to have to get past this step. Install the chromedriver and put it inside a folder on your desktop. Also make sure to put the selenium python project in the same folder as where the chrome driver is located.
2020 年的答案。以下代码解决了这个问题。很多刚接触硒的人似乎必须通过这一步。安装 chromedriver 并将其放在桌面上的文件夹中。还要确保将 selenium python 项目放在与 chrome 驱动程序所在的文件夹相同的文件夹中。
Change USER_NAME and FOLDER in accordance to your computer.
根据您的计算机更改 USER_NAME 和 FOLDER。
For Windows
对于 Windows
driver = webdriver.Chrome(r"C:\Users\USER_NAME\Desktop\FOLDER\chromedriver")
For Linux/Mac
对于 Linux/Mac
driver = webdriver.Chrome("/home/USER_NAME/FOLDER/chromedriver")
回答by mamal
try this :
尝试这个 :
driver = webdriver.Chrome(ChromeDriverManager().install())
回答by Desmend Jetton
Another way is download and unzip chromedriver and put 'chromedriver.exe' in C:\Python27\Scripts and then you need not to provide the path of driver, just
另一种方法是下载并解压chromedriver并将'chromedriver.exe'放在C:\Python27\Scripts中,然后你不需要提供驱动程序的路径,只需
driver= webdriver.Chrome()
will work
将工作
Can testify that this also works for Python3.7.
可以证明这也适用于 Python3.7。