Mac中安装好selenium,webdriver后,运行简单脚本时报错E ModuleNotFoundError: No module named 'http.client'

import selenium
from selenium import webdriver

def test_selenium():
driver = webdriver.Chrome()
driver.get(“https://www.baidu.com”)

报错如下:
test_selenium.py:None (test_selenium.py)
ImportError while importing test module ‘/Users/zhanzhoumin/PycharmProjects/practice/test_add/test_selenium.py’.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
…/venv/lib/python3.7/site-packages/_pytest/python.py:511: in _importtestmodule
mod = self.fspath.pyimport(ensuresyspath=importmode)
…/venv/lib/python3.7/site-packages/py/_path/local.py:701: in pyimport
import(modname)
…/venv/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:152: in exec_module
exec(co, module.dict)
test_selenium.py:2: in
from selenium import webdriver
…/venv/lib/python3.7/site-packages/selenium/webdriver/init.py:18: in
from .firefox.webdriver import WebDriver as Firefox # noqa
…/venv/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py:29: in
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
…/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py:27: in
from .remote_connection import RemoteConnection
…/venv/lib/python3.7/site-packages/selenium/webdriver/remote/remote_connection.py:24: in
import urllib3
…/venv/lib/python3.7/site-packages/urllib3/init.py:7: in
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
…/venv/lib/python3.7/site-packages/urllib3/connectionpool.py:11: in
from .exceptions import (
…/venv/lib/python3.7/site-packages/urllib3/exceptions.py:2: in
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
…/venv/lib/python3.7/site-packages/urllib3/packages/six.py:199: in load_module
mod = mod._resolve()
…/venv/lib/python3.7/site-packages/urllib3/packages/six.py:113: in _resolve
return _import_module(self.mod)
…/venv/lib/python3.7/site-packages/urllib3/packages/six.py:82: in _import_module
import(name)
E ModuleNotFoundError: No module named ‘http.client’
collected 0 items / 1 error

看一下你项目里是不是有http这种与引用包名重复的文件夹或者文件 导致无法找到正确对应的包

代码尽量格式化吧,不然看着眼睛疼。

看报错是模块之中引用其他模块导致的问题,可以先把venv的模块全部清理掉,然后重新导入看看能不能解决问题

是的,找到了原因了,确实重名了,谢谢老师指点:pray:

小白感谢大神指教哈,谢谢:pray:

关闭