124

Error message:

'chromedriver' executable needs to be in 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).

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?

By the way, I tried typing "chromedriver" in cmd, however, it wasn't recognized as an internal or external command.

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'
Sebastian Nielsen
  • 3,835
  • 5
  • 27
  • 43

7 Answers7

189

You can download ChromeDriver here: https://sites.google.com/chromium.org/driver/

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')
    
Community
  • 1
  • 1
Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99
  • 3
    Every browser has/needs its own driver, there is no IE on Linux or Safari on Windows. Selenium is just a tool which enables to you to "talk" to the browser. – Maximilian Peters Nov 11 '16 at 21:07
  • 2
    A new error raised after I added chromedriver to the path. Can you spot what the problem is? Its something about, "permission denied." How do I give it permission? – Sebastian Nielsen Nov 11 '16 at 21:12
  • 1
    Did you give the full path to the exe or just the path? You need the location of the exe file. If the problem persists search for the error message here, I am sure somebody encountered the same problem before. – Maximilian Peters Nov 11 '16 at 21:33
  • I simply dropped it into my python folder. https://gyazo.com/04fcef5ee8ef8fa29ae9e16abfcb556f I suppose that wasnt correct since it aint working? – Sebastian Nielsen Nov 11 '16 at 21:37
  • try copying chromedriver.exe in your python script directory, it might be that you need to start the script as admin if it is located in a program directory. – Maximilian Peters Nov 11 '16 at 21:55
  • I am sorry, but isnt that what I already did, copied it to the python directory? As seen on the photo – Sebastian Nielsen Nov 11 '16 at 21:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127927/discussion-between-sebastian-and-maximilian-peters). – Sebastian Nielsen Nov 11 '16 at 21:58
  • Hi, I am experiencing the same error message but can't seem to fix it. What can I do? Not that it helps much but this is the line of code I am currently using: driver = webdriver.Chrome(executable_path='~ Misha$ /Users/Misha/chromedriver.exe') – bernando_vialli Jul 21 '18 at 14:03
  • 1
    @mkheifetz Your path looks malformed, try `executable_path='/Users/Misha/chromedriver.exe'` or check if the file exists with `os.path.exists()` – Maximilian Peters Jul 22 '18 at 07:53
  • @MaximilianPeters that does not seem to work. I am doing this on a mac, would that change my code, and how if so? – bernando_vialli Jul 22 '18 at 14:57
  • 4
    @mkheifetz If you are using a Mac, the chromedriver files doesn't have a file extension, so it should be '/Users/Misha/chromedriver'. But try assigning it to a variable and then check if `os.path.exists(chromedriver_path)` returns `True`. – Maximilian Peters Jul 22 '18 at 15:19
  • Thank you, that seems to have fixed that problem! However, when I execute my code trying to post 1000 questions from an excel file to a website, it gives me some gibberish output and goes to the website where it's supposed to put in the login and password to proceed, but instead if just keeps refreshing the page over and over again. Any idea why? – bernando_vialli Jul 22 '18 at 15:53
  • @mkheifetz: Please post it as new question and include a [MCVE]. – Maximilian Peters Jul 23 '18 at 19:00
  • I disagree. You should use os.chdir(os.path.dirname(__file__)) in front of your code – Jelani Feb 13 '21 at 01:36
  • This solution is deprecated – Camillo May 22 '22 at 22:20
  • As @Camillo mentioned specifying executable_path directly is now deprecated. You now need to import the Service class via: `from selenium.webdriver.chrome.service import Service` then `driver = webdriver.Chrome(service=Service(r'C:/path/to/chromedriver.exe')` – kowpow Jan 18 '23 at 16:31
64

Try this :

pip install webdriver-manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
Undo
  • 25,519
  • 37
  • 106
  • 129
BUGATTI AJAY
  • 759
  • 6
  • 3
33

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

driver= webdriver.Chrome()

will work

thebadguy
  • 2,092
  • 1
  • 22
  • 31
  • "'Service' object has no attribute 'process'" in > ignored – Sohail Sep 24 '18 at 16:37
  • @Sohail, can you explain your comment more – thebadguy Sep 24 '18 at 18:08
  • fp = webdriver.FirefoxProfile() fp.set_preference("browser.download.folderList",2) fp.set_preference("browser.download.manager.showWhenStarting",False) # fp.set_preference("browser.download.dir",getcwd()) fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv") self.browser= webdriver.Firefox(firefox_profile=fp)It says OSError: [Errno 8] Exec format error and sometime the above – Sohail Sep 24 '18 at 18:14
  • 1
    @Sohail, can you ask it as a question and paste the link of that question, as the code is not readable in comments – thebadguy Sep 24 '18 at 18:22
  • https://stackoverflow.com/questions/52490692/selenium-firefox-driver-raise-exception-oserror-errno-8-exec-format-error – Sohail Sep 25 '18 at 04:43
14

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.

Change USER_NAME and FOLDER in accordance to your computer.

For Windows

driver = webdriver.Chrome(r"C:\Users\USER_NAME\Desktop\FOLDER\chromedriver")

For Linux/Mac

driver = webdriver.Chrome("/home/USER_NAME/FOLDER/chromedriver")
minTwin
  • 1,181
  • 2
  • 21
  • 35
  • 2
    im going to throw in, having come across this while googling fthat for Windows, Chocolately has ChromeDriver which makes it easier to keep updated with simply commant: https://chocolatey.org/install and then you can just use `choco install chromedriver` – CeePlusPlus Jan 12 '22 at 21:01
9

Do not include the '.exe' in your file path.

For example:

from selenium import webdriver

driver = webdriver.Chrome(executable_path='path/to/folder/chromedriver')
Erich Purpur
  • 1,337
  • 3
  • 14
  • 34
6

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

driver= webdriver.Chrome()

will work

Can testify that this also works for Python3.7.

6

try this :

driver = webdriver.Chrome(ChromeDriverManager().install())
mamal
  • 1,791
  • 20
  • 14
  • `pip install webdriver-manager` in cmd/terminal first, then `from webdriver_manager.chrome import ChromeDriverManager` in python file, then as you said – lam vu Nguyen Feb 11 '23 at 17:13