文件命名导致的No module named ‘http.client‘错误

做一个小功能,用python命令行发送GET请求。

建了个目录,随手给程序文件命名成http.py

打开cmd命令,进入该目录,安装requests包,进入python命令行,进行测试。

敲入第一条命令:import requests,报错:

Traceback (most recent call last):
  File "", line 1, in
  File "c:\python37\lib\site-packages\requests\__init__.py", line 43, in
    import urllib3
  File "c:\python37\lib\site-packages\urllib3\__init__.py", line 11, in
    from . import exceptions
  File "c:\python37\lib\site-packages\urllib3\exceptions.py", line 3, in
    from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
  File "c:\python37\lib\site-packages\urllib3\packages\six.py", line 199, in load_module
    mod = mod._resolve()
  File "c:\python37\lib\site-packages\urllib3\packages\six.py", line 113, in _resolve
    return _import_module(self.mod)
  File "c:\python37\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
    __import__(name)
ModuleNotFoundError: No module named 'http.client'; 'http' is not a package

按报错信息去搜索,遇到这问题的人还真不少,但没有什么好的解决办法。

有人说可能是http包有问题,突然看见自己建的http.py文件,突然明白了什么。把名字改了,一切正常。

看来给文件命名时,必须绕开一些关键词汇。

你可能感兴趣的:(文件命名导致的No module named ‘http.client‘错误)