【问题标题】:Error while installing Selenium in pip3在 pip3 中安装 Selenium 时出错
【发布时间】:2017-03-11 00:20:08
【问题描述】:

我正在尝试安装 selenium,但似乎有问题:

我运行 pip3 install -U selenium,得到:

    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'

尽管有这条消息,我可以继续并在 python3 中运行 selenium,以及类似的命令

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

将返回

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.

我需要做什么?

【问题讨论】:

    标签: python-3.x selenium package pip


    【解决方案1】:

    您是否尝试以超级用户身份运行 pip install ?当您错过sudo 时,通常会出现 PermissionError。如果没有,请尝试sudo pip3 install -U selenium

    【讨论】:

    • 我读到 sudo pip 是一种不安全的做法,所以我想避免它。不过,这些错误看起来确实表明存在权限问题,所以你认为这是我最好的选择吗?而且我假设不安全性仅在安装过程中发生,因此我不必担心像 selenium 这样被广泛接受的软件包。
    • 我已经使用 sudo 和 pip 很长时间了,从来没有遇到过问题。另外,我见过真正的专家使用它。实际上,从未听说过它不安全。 Linux 上的 /usr/ 文件夹不能在没有超级用户权限的情况下修改,所以是的,这是我为您解决安装问题的最佳选择。希望它有效:)。
    • 现在可以使用了!我必须运行sudo -H pip3 install seleniumbrew install geckodriver
    • 太好了!!恭喜:)
    【解决方案2】:

    也可以不以超级用户身份执行 pip (which you should, at least, try not to):

    创建目录:

    sudo mkdir /usr/local/selenium
    

    给自己目录的所有权:

    chown your_username /usr/local/selenium
    

    安装硒:

    pip3 install -U selenium
    

    【讨论】:

    • 啊,谢谢,这就是我正在寻找的答案 :)
    猜你喜欢
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 2019-04-14
    相关资源
    最近更新 更多