3

I am attempting to install selenium, and yet there seems to be a problem:

I ran pip3 install -U selenium, and I get:

    Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python3.5/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/usr/local/lib/python3.5/site-packages/pip/req/req_set.py", line 742, in install
    **kwargs
  File "/usr/local/lib/python3.5/site-packages/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/local/lib/python3.5/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "/usr/local/lib/python3.5/site-packages/pip/wheel.py", line 378, in move_wheel_files
    clobber(source, dest, False, fixer=fixer, filter=filter)
  File "/usr/local/lib/python3.5/site-packages/pip/wheel.py", line 317, in clobber
    ensure_dir(destdir)
  File "/usr/local/lib/python3.5/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/local/Cellar/python3/3.5.2_2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/usr/local/Cellar/python3/3.5.2_2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/usr/local/Cellar/python3/3.5.2_2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/os.py", line 231, in makedirs
makedirs(head, mode, exist_ok)
  File "/usr/local/Cellar/python3/3.5.2_2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/selenium'

Despite this message, I can proceed and run selenium in python3, and a command like

from selenium import web driver
browser = webdriver.Firefox()

will return

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
  File "/usr/local/Cellar/python3/3.5.2_2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
  File "/usr/local/Cellar/python3/3.5.2_2/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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
  File "/usr/local/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.

What do I need to do?

Joseph K.
  • 1,055
  • 3
  • 23
  • 46

2 Answers2

3

It can also be done without executing pip as superuser (which you should, at least, try not to):

Create the directory:

sudo mkdir /usr/local/selenium

Give yourself ownership of the directory:

chown your_username /usr/local/selenium

Install Selenium:

pip3 install -U selenium
Community
  • 1
  • 1
andresgottlieb
  • 920
  • 10
  • 18
0

Did you try to run pip install as a super user? It's common to have PermissionError when you miss the sudo. If you didn't, try sudo pip3 install -U selenium.

vribeiro
  • 161
  • 6
  • I read about sudo pip to be an insecure practice, so I wanted to avoid it. The errors do appear like it is indicating a permission issue though, so do you suggest that's my best bet? and I'm assuming that the insecurity is during installation only, so I shouldn't have to worry for a widely accepted package like selenium. – Joseph K. Oct 28 '16 at 20:28
  • I've been using sudo with pip for a long time and never got problems with it. Also, I've seen real experts using this. Actually, never heard about it being insecure. The /usr/ folder on Linux can't be modified without super user privileges, so yep, this is my best bet for you installation problem. Hope it works :). – vribeiro Oct 28 '16 at 20:33
  • It's working now! I had to run `sudo -H pip3 install selenium` and also `brew install geckodriver` – Joseph K. Oct 29 '16 at 08:00
  • That's great!! Congrats :) – vribeiro Oct 29 '16 at 11:54