当我安装 Selenium 时出现以下错误:
Shubham@Shubham-To-be-filled-by-O-E-M:~$ sudo apt-get update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Hit:2 https://repo.skype.com/deb stable InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Get:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Fetched 323 kB in 8s (38.6 kB/s)
Reading package lists... Done
Shubham@Shubham-To-be-filled-by-O-E-M:~$ sudo pip install selenium
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
我该如何继续?
答案1
Selenium 可从 Ubuntu 16.04 及更高版本的默认 Ubuntu 存储库中获得。要安装 selenium,请打开终端并输入:
sudo apt install python-selenium # for Python 2.x
和/或
sudo apt install python3-selenium # for Python 3.x
然后输入python
以启动 Python 解释器,其from selenium import webdriver
工作方式如下:
$Python >>> 从 selenium 导入 webdriver
假设该路径~/.local/bin
在您的执行 PATH 中,下面是如何安装名为 geckodriver 的 Firefox webdriver:
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