没有名为“urllib3”Selenium Python的模块

问题描述 投票:0回答:2

我之前和Selenium一起工作过,一切都很好,但突然间它停止了工作。我试图重新安装Python,Selenium和更新的pip。当我运行这个简单的Python Selenium脚本时:

from selenium import webdriver
from time import sleep
driver = webdriver.Chrome('drivers/chromedriver.exe')
driver.get("http://www.python.org")
sleep(5)

它返回以下错误消息:

Traceback (most recent call last):
  File "C:\Users\Jan\Desktop\Python\Selenium\test.py", line 1, in <module>
    from selenium import webdriver
  File "C:\Users\Jan\Desktop\Python\Selenium\selenium\webdriver\__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "C:\Users\Jan\Desktop\Python\Selenium\selenium\webdriver\firefox\webdriver.py", line 29, in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  File "C:\Users\Jan\Desktop\Python\Selenium\selenium\webdriver\remote\webdriver.py", line 27, in <module>
    from .remote_connection import RemoteConnection
  File "C:\Users\Jan\Desktop\Python\Selenium\selenium\webdriver\remote\remote_connection.py", line 24, in <module>
    import urllib3
ModuleNotFoundError: No module named 'urllib3'

有什么我想念的吗?谢谢你的帮助。

python selenium pip
2个回答
0
投票

看起来好像没有安装urllib3。

尝试在终端输入pip install urllib3

另一种解决方案可能是正确激活您的环境变量为此,请在终端中键入source [env]/bin/activate


0
投票

由于Selenium 3.14.0 Selenium已经为urllib3换出了httplib。

但是这个错误信息......

    import urllib3
ModuleNotFoundError: No module named 'urllib3'

...暗示Python客户端无法导入urllib3。

但是我怀疑主要问题是使用由您的系统软件包管理器安装的较旧版本的pip,并且可以用更新版本的pip替换。

pip升级到最新版本(至少v18.0)将解决您的问题。

C:\Users\myUser>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
© www.soinside.com 2019 - 2024. All rights reserved.