我通过命令安装了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命令时,我可以确认python 3已经安装,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.
>>>
在不知道操作系统及其版本的情况下,这将是一个猜测答案:(
我敢打赌你运行的是旧版Fedora还是CentOS?
如果是这样的话,HTTPie版本非常旧(0.9.4(,当时它是使用Python 2捆绑的。因此,当您执行sudo yum install httpie
时,它将安装可作为Python 2模块执行的http
和https
。
在评论中提出的一个解决方案是使用python3 -m pip install --upgrade httpie
:它将确保您正在为Python3安装HTTPie。并且http
&https
可执行文件也将可用。如果执行此操作,则必须首先删除通过yum
安装的HTTPie版本。