You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04下无法安装http及request模块求助

问题解决:安装http模块失败及request模块找不到的问题

环境信息

  • Ubuntu 22.04
  • Python 3.10.6
  • pip 22.0.2

操作与错误详情

执行拼写错误的安装命令:

pip install htttp

实际触发安装PyPI上的http包,过程中报错:

Collecting http
Downloading http-0.02.tar.gz (32 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [31 lines of output]
Traceback (most recent call last):
File "", line 2, in
File "", line 34, in
File "/tmp/pip-install-wt_twpw1/http_e204a51ec15142428e42fe97cce6fbe8/setup.py", line 3, in
import http
File "/tmp/pip-install-wt_twpw1/http_e204a51ec15142428e42fe97cce6fbe8/http/init.py", line 17, in
from request import Request
ModuleNotFoundError: No module named 'request'
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
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in
from urllib.request import urlopen
File "/usr/lib/python3.10/urllib/request.py", line 88, in
import http.client
File "/tmp/pip-install-wt_twpw1/http_e204a51ec15142428e42fe97cce6fbe8/http/init.py", line 17, in
from request import Request
ModuleNotFoundError: No module named 'request'

随后尝试安装request模块,同样失败:

pip install request

错误信息:

ERROR: Could not find a version that satisfies the requirement request (from versions: none)
ERROR: No matching distribution found for request

解决方案

  1. 无需安装http模块:Python标准库已内置http模块,直接在代码中import http即可使用,不必通过pip安装第三方的http包——该包本身存在依赖问题,且功能完全被标准库覆盖。
  2. 正确的HTTP第三方库是requests:不存在名为request的PyPI包,若需使用第三方HTTP请求工具,安装requests(注意末尾有s):
pip install requests
  1. 修正命令拼写:最初的命令pip install htttp多打了一个t,即便要安装第三方包也应为pip install http,但不建议安装该包。

内容的提问来源于stack exchange,提问作者monster-dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 00:45:39