运行 Ubuntu Server 22.04,当我尝试运行我一直在使用的 python 脚本时出现此错误。最简单的情况实际上就是:
import requests
这似乎是系统范围内发生的,即使对于使用自己的虚拟环境的脚本也是如此,这非常奇怪。直到今天一切都运行良好,而且我最近没有弄乱 pip 或 python 包。尝试查找它,但没有找到任何相关内容。这是我尝试运行以下脚本时的完整输出:import requests
Traceback (most recent call last):
File "/home/mahmoud/http_python_test.py", line 1, in <module>
import requests
File "/home/mahmoud/.local/lib/python3.10/site-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/__init__.py", line 11, in <module>
from . import exceptions
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/exceptions.py", line 3, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/packages/six.py", line 199, in load_module
mod = mod._resolve()
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/packages/six.py", line 113, in _resolve
return _import_module(self.mod)
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/packages/six.py", line 82, in _import_module
__import__(name)
ModuleNotFoundError: No module named 'http.client'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
from urllib.request import urlopen
File "/usr/lib/python3.10/urllib/request.py", line 88, in <module>
import http.client
ModuleNotFoundError: No module named 'http.client'
Original exception was:
Traceback (most recent call last):
File "/home/mahmoud/http_python_test.py", line 1, in <module>
import requests
File "/home/mahmoud/.local/lib/python3.10/site-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/__init__.py", line 11, in <module>
from . import exceptions
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/exceptions.py", line 3, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/packages/six.py", line 199, in load_module
mod = mod._resolve()
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/packages/six.py", line 113, in _resolve
return _import_module(self.mod)
File "/home/mahmoud/.local/lib/python3.10/site-packages/urllib3/packages/six.py", line 82, in _import_module
__import__(name)
ModuleNotFoundError: No module named 'http.client'