[英]No module named “urllib3” Selenium Python
我以前與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'
我有什么想念的嗎? 謝謝你的幫助。
似乎未安裝urllib3。
嘗試在終端中輸入pip install urllib3
。
另一個解決方案可能是正確激活您的環境變量。 為此,請在終端中鍵入source [env]/bin/activate
。
從Selenium 3.14.0開始, Selenium已將httplib換成urllib3 。
但是這個錯誤信息...
import urllib3
ModuleNotFoundError: No module named 'urllib3'
...表示Python客戶端無法導入urllib3 。
但是,我懷疑主要問題是系統軟件包管理器已安裝了較舊版本的pip
,並且可以用較新版本的pip代替。
將pip
升級到最新版本(atleast v 18.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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.