-3

我通过命令安装了 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 命令时的 python shell

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.
>>>
4

1 回答 1

1

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

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

如果是这种情况,HTTPie 版本非常旧(0.9.4),当时它是使用 Python 2 捆绑的。所以当你这样做时sudo yum install httpie,它将作为 Python 2 模块安装http和执行。https

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

于 2021-07-06T08:39:41.920 回答