简体   繁体   中英

Python - Selenium in Ubuntu OSError: [Errno 20] Not a directory

After installing Selenium in Ubuntu and adding geckodriver to path I get this error when I run

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.

Had the same problem. There were two ways to fix this for me:

Add executable_path arg in webdriver:

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):

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

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 .

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.

The problem is that you renamed "geckodriver" to "wires".

The solution is to add "geckodriver" to search path then it should work.

除了提供的答案之外,还有一个选项可以将驱动程序复制到/usr/bin

sudo cp geckodriver /usr/bin 

Selenium is available from the default Ubuntu repositories in Ubuntu 16.04 and later. To install selenium open the terminal and type:

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  
>>> 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:

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

source: https://askubuntu.com/questions/1041541/i-want-to-install-selenium-webdriver-in-my-ubuntu-16-04-system-for-python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM