安装 python 3 后,httpie 仍然使用 python 2.7

httpie still use python 2.7 when python 3 is installed

我通过命令安装了 httpie

sudo yum install httpie

python3 命令在 PATH 上。但是当我 运行 http 命令时它仍然使用 python 2.7 导致错误。

http 命令错误

    Traceback (most recent call last):
  File "/usr/bin/http", line 9, in <module>
    load_entry_point('httpie==0.9.4', 'console_scripts', 'http')()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/site-packages/httpie/__main__.py", line 5, in <module>
    from .core import main
  File "/usr/lib/python2.7/site-packages/httpie/core.py", line 17, in <module>
    import requests
  File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/usr/lib/python2.7/site-packages/requests/utils.py", line 32, in <module>
    from .exceptions import InvalidURL
  File "/usr/lib/python2.7/site-packages/requests/exceptions.py", line 10, in <module>
    from urllib3.exceptions import HTTPError as BaseHTTPError
  File "/usr/lib/python2.7/site-packages/urllib3/__init__.py", line 10, in <module>
    from .connectionpool import (
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 31, in <module>
    from .connection import (
  File "/usr/lib/python2.7/site-packages/urllib3/connection.py", line 45, in <module>
    from .util.ssl_ import (
  File "/usr/lib/python2.7/site-packages/urllib3/util/__init__.py", line 5, in <module>
    from .request import make_headers
  File "/usr/lib/python2.7/site-packages/urllib3/util/request.py", line 5, in <module>
    from ..exceptions import UnrewindableBodyError
ImportError: cannot import name UnrewindableBodyError

我可以确认 python 3 已安装,python shell 当我 运行 python 命令

Python 3.8.5 (default, Sep  4 2020, 07:30:14)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

在不知道您的 OS 及其版本的情况下,这将是一个猜测答案:)

我打赌你是 运行 旧的 Fedora 版本或 CentOS?

如果是这样,HTTPie 版本很旧 (0.9.4),当时它是使用 Python 2 捆绑的。所以当您执行 sudo yum install httpie 时,它将安装 httphttps 可执行为 Python 2 个模块。

评论中提出的一个解决方案是使用 python3 -m pip install --upgrade httpie:它将确保您正在为 Python 3 安装 HTTPie。并且 http & https 可执行文件也将可用。如果这样做,您必须先删除通过 yum.

安装的 HTTPie 版本