首页 > 解决方案 > 每次使用 Python 打开和执行新项目时,我们是否需要安装 Selenium?

问题描述

我在 python 项目中安装了 selenium 和 chrome 驱动程序,当我创建一个新项目时说它无法识别 selenium 模块。

这是否意味着每个项目我都需要再次安装 selenium?

标签: pythonseleniumselenium-webdrivermodulewebdriver

解决方案


,您不需要为每个项目安装Selenium。安装过程一生中只有一次,通过命令行界面使用以下命令之一:

  • 使用点子

    pip install selenium
    
  • 使用pip3

    pip3 install selenium
    

升级点

但是,您需要继续定期升级 pip :

  • 上:

    pip install -U pip
    
  • python -m pip install -U pip
    
  • 或者

    C:\Users\username>python -m pip install --upgrade pip
    Collecting pip
      Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
      100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.3MB 544kB/s
    Installing collected packages: pip
      Found existing installation: pip 10.0.1
        Uninstalling pip-10.0.1:
          Successfully uninstalled pip-10.0.1
    Successfully installed pip-18.0
    

升级硒

作为一项强制性措施,您需要升级Selenium绑定以与每个稳定版本的发布保持同步,如下所示:

C:\Users\username>pip install -U selenium
Collecting selenium
  Downloading https://files.pythonhosted.org/packages/b8/53/9cafbb616d20c7624ff31bcabd82e5cc9823206267664e68aa8acdde4629/selenium-3.14.0-py2.py3-none-any.whl (898kB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 901kB 380kB/s
Requirement not upgraded as not directly required: urllib3 in c:\python\lib\site-packages (from selenium) (1.22)
Installing collected packages: selenium
  Found existing installation: selenium 3.12.0
    Uninstalling selenium-3.12.0:
      Successfully uninstalled selenium-3.12.0
Successfully installed selenium-3.14.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

参考

您可以在以下位置找到详细的相关讨论:


推荐阅读