Python - Ubuntu OSError 中的 Selenium:[Errno 20] 不是目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40073548/
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
Python - Selenium in Ubuntu OSError: [Errno 20] Not a directory
提问by User
After installing Selenium in Ubuntu and adding geckodriver to path I get this error when I run
在 Ubuntu 中安装 Selenium 并将 geckodriver 添加到路径后,我在运行时收到此错误
from selenium import webdriver
driver = webdriver.Firefox()
error:
错误:
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
What's going on?
这是怎么回事?
EDIT: Solved using chromedriver instead of geckodriver.
编辑:使用 chromedriver 而不是 geckodriver 解决。
回答by Poloq
Had the same problem. There were two ways to fix this for me:
有同样的问题。有两种方法可以为我解决这个问题:
Add executable_path arg in webdriver:
在 webdriver 中添加 executable_path arg:
driver = webdriver.Firefox(executable_path='/path/to/geckodriver')
And the second way its to add folder that contains geckodriver using export (only folder, not geckodriver):
第二种方法是使用导出添加包含 geckodriver 的文件夹(仅文件夹,而不是 geckodriver):
$ export PATH=$PATH:/path/to/
回答by dsalaj
In addition to the answer by @Poloq, the simplest way would be keeping your geckodriver
binary in a directory which is already in your PATH
.
除了@Poloq 的答案之外,最简单的方法是将geckodriver
二进制文件保存在PATH
.
mv geckodriver /usr/local/bin
This way you can avoid additional settings/configurations in your project with the downside of having an additional step when deploying on different systems.
通过这种方式,您可以避免项目中的其他设置/配置,但缺点是在不同系统上部署时需要额外的步骤。
回答by Kamil W.
The problem is that you renamed "geckodriver" to "wires".
问题是您将“geckodriver”重命名为“wires”。
The solution is to add "geckodriver" to search path then it should work.
解决方案是将“geckodriver”添加到搜索路径然后它应该可以工作。
回答by Billal Begueradj
In addition to the provided answers, there is also this option where you can copy the driver to /usr/bin
:
除了提供的答案之外,还有这个选项,您可以将驱动程序复制到/usr/bin
:
sudo cp geckodriver /usr/bin
回答by puroh
Selenium is available from the default Ubuntu repositories in Ubuntu 16.04 and later. To install selenium open the terminal and type:
Selenium 可从 Ubuntu 16.04 及更高版本的默认 Ubuntu 存储库中获得。要安装 selenium,请打开终端并输入:
sudo apt install python-selenium # for Python 2.x
and/or
和/或
sudo apt install python3-selenium # for Python 3.x
Then type python to start the Python interpreter and from selenium import webdriver should work like this:
然后输入 python 来启动 Python 解释器, from selenium import webdriver 应该像这样工作:
$ python
>>> from selenium import webdriver
Assuming that the path ~/.local/bin is in your execution PATH, here's how to install the Firefox webdriver, called geckodriver:
假设路径 ~/.local/bin 在你的执行 PATH 中,这里是如何安装 Firefox webdriver,称为 geckodriver:
wget https://github.com/mozilla/geckodriver/releases/download/v0.20.1/geckodriver-v0.20.1-linux64.tar.gz
tar xvfz geckodriver-v0.20.1-linux64.tar.gz
mv geckodriver ~/.local/bin
来源:https: //askubuntu.com/questions/1041541/i-want-to-install-selenium-webdriver-in-my-ubuntu-16-04-system-for-python