【问题标题】:Can't run run script due to ModuleNotFoundError: No module named 'webdriver_manager' Ubuntu Python由于 ModuleNotFoundError 无法运行运行脚本:没有名为“webdriver_manager”的模块 Ubuntu Python
【发布时间】:2021-01-13 16:04:15
【问题描述】:

我正在使用 anaconda、jupyter 并安装了 pip 和 pip3 webdriver_manager,但是当我尝试运行我的 python3 代码时,我不断收到此错误。当我在终端运行代码时

$ pip install webdriver_manager
Collecting webdriver_manager
  Using cached https://files.pythonhosted.org/packages/dd/3c/2e2d71aeb28ee73ecaf12b545542b082ca81c8c091bb05028c52c42696ce/webdriver_manager-2.4.0-py2.py3-none-any.whl
Collecting requests (from webdriver_manager)
  Using cached https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl
Collecting configparser (from webdriver_manager)
  Using cached https://files.pythonhosted.org/packages/7a/2a/95ed0501cf5d8709490b1d3a3f9b5cf340da6c433f896bbe9ce08dbe6785/configparser-4.0.2-py2.py3-none-any.whl
Collecting crayons (from webdriver_manager)
  Using cached https://files.pythonhosted.org/packages/5b/0d/e3fad4ca1de8e70e06444e7d777a5984261e1db98758b5be3e8296c03fe9/crayons-0.4.0-py2.py3-none-any.whl
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests->webdriver_manager)
  Using cached https://files.pythonhosted.org/packages/9f/f0/a391d1463ebb1b233795cabfc0ef38d3db4442339de68f847026199e69d7/urllib3-1.25.10-py2.py3-none-any.whl
Collecting chardet<4,>=3.0.2 (from requests->webdriver_manager)
  Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests->webdriver_manager)
  Using cached https://files.pythonhosted.org/packages/5e/c4/6c4fe722df5343c33226f0b4e0bb042e4dc13483228b4718baf286f86d87/certifi-2020.6.20-py2.py3-none-any.whl
Collecting idna<3,>=2.5 (from requests->webdriver_manager)
  Using cached https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl
Collecting colorama (from crayons->webdriver_manager)
  Using cached https://files.pythonhosted.org/packages/c9/dc/45cdef1b4d119eb96316b3117e6d5708a08029992b2fee2c143c7a0a5cc5/colorama-0.4.3-py2.py3-none-any.whl
Installing collected packages: urllib3, chardet, certifi, idna, requests, configparser, colorama, crayons, webdriver-manager
Successfully installed certifi-2020.6.20 chardet-3.0.4 colorama-0.4.3 configparser-4.0.2 crayons-0.4.0 idna-2.10 requests-2.24.0 urllib3-1.25.10 webdriver-manager-2.4.0

在我的 IDE 中,我得到了这个输出

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import requests
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from webdriver_manager.firefox import GeckoDriverManager

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-87a373070a15> in <module>
      9 import requests
     10 from selenium.webdriver.firefox.options import Options as FirefoxOptions
---> 11 from webdriver_manager.firefox import GeckoDriverManager

ModuleNotFoundError: No module named 'webdriver_manager'

我一直在尝试在 SO 上发布的几种解决方案,但都没有解决问题

【问题讨论】:

    标签: python-3.x ubuntu selenium-webdriver firefox jupyter-notebook


    【解决方案1】:

    我遇到了同样的问题。在我的情况下,解决方案是python3.8 -m pip install webdriver_manager,现在它可以工作了

    【讨论】:

    • 所以如果我有 python 3.6.9 那么我会用你提供的其余代码来补充它?
    • 我认为您应该尝试输入python3.6 -m pip install webdriver_manager,它应该可以解决问题。我有几次类似的情况,当我试图为 python3.8 安装包并输入 pip install package 然后意识到我刚刚为 python2.7 安装了包:D
    • 刚刚尝试了你的方法,似乎没有成功,dang
    • 如果我卸载 python 2.7 会有帮助吗?甚至更新到更高版本的 python 3?
    • 老实说,更好的方法是开始使用最新版本,如果您不需要使用 python2.7,只需安装 python3.8,一切都会正常
    【解决方案2】:

    如果您使用 Visual Studio Code,还有另一种解决方案;

    VSCode 有时无法自动完成某些 python 包,这会导致导入失败,即使它们在从 CLI 运行时正确运行也是如此。这种情况经常发生。解决方法是在 VSCode settings.json 的自动补全路径列表中添加这样的路径。

    settings.json 位于:

    • Windows:%APPDATA%\Code\User\settings.json
    • ma​​cOS:$HOME/Library/Application Support/Code/User/settings.json
    • Linux:$HOME/.config/Code/User/settings.json

    并将webdriver_manager包的路径添加到python.autoComplete.extraPaths中,本例中的路径如下:

    {
       "editor.suggestSelection": "first",
       "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
       "git.autofetch": true,
       "python.languageServer": "Microsoft",
       "python.autoComplete.extraPaths": [
           "path/to/webdriver_manager"
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      相关资源
      最近更新 更多