Python – Selenium在Ubuntu OSError:不是目录

在Ubuntu中安装Selenium并添加geckodriver到path后,我得到这个错误,当我运行

from selenium import webdriver driver = webdriver.Firefox() 

错误:

 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__ self.service.start() File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 64, in start stdout=self.log_file, stderr=self.log_file) File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 20] Not a directory 

这是怎么回事?

编辑:解决使用chromedriver而不是geckodriver。

有同样的问题。 有两种方法可以解决这个问题:

在webdriver中添加executable_path arg:

 driver = webdriver.Firefox(executable_path='/path/to/geckodriver') 

第二种方式来添加包含geckodriver使用导出文件夹(只有文件夹,而不是geckodriver):

 $ export PATH=$PATH:/path/to/ 

除了@Poloq的回答之外,最简单的方法是将geckodriver二进制文件保存在PATH中的一个目录中。

 mv geckodriver /usr/local/bin 

通过这种方式,您可以避免在项目中进行额外的设置/配置,而在不同的系统上进行部署时可能需要额外的步骤。

问题是你把“geckodriver”改名为“wires”。

解决方法是添加“geckodriver”搜索路径然后它应该工作。