web-dev-qa-db-fra.com

Comment mettre geckodriver dans PATH?

Je suis sous OS Sierra et j'utilise Python 3.5.2. J'ai installé Selenium et je suis un livre intitulé "Automatisez les tâches ennuyeuses avec Python"

Mon code est 

from Selenium import webdriver
>>> browser = webdriver.Firefox()

Je continue à recevoir l'erreur 

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
browser = webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
Selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

J'ai cherché très loin des solutions à mon problème. Beaucoup de gens ont le même problème .. mais aucune des solutions ne fonctionne. J'ai copié geckodriver partout dans mes dossiers Python. J'ai essayé d'utiliser terminal et j'ai essayé de spécifier le chemin dans le code et cela me donne toujours des erreurs. J'espère que quelqu'un peut m'aider. Je suis désolé si le format est incorrect, je ne sais pas ce que je fais.

8
Matthew Garcia

J'ai rencontré le même problème et voici comment je l'ai résolu:

  1. Téléchargez la geckodriver de ici
  2. Extrayez, décompressez et déplacez le fichier geckodriver dans le répertoire /usr/local/bin/
  3. Exécutez le programme python avec Selenium Firefox webdriver.
14
kiran.koduru

"Geckodriver est copié partout dans mes dossiers Python."

import sys
print sys.path

Et le problème devrait être résolu.

1
TheoretiCAL

Cette réponse peut être facilement résolue par une recherche Google pour "add program to path"

export PATH=$PATH:/path/to/geckodriver
1
sircapsalot