如何从 python 中删除请求并在 pip 中安装

如何从 python 中删除请求并在 pip 中安装

我需要在 pip 中引用请求,但它已经在 python 中安装了。

 Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.18.4)

我怎样才能将请求更改为 pip?

  • Ubuntu 版本:18.04.2 LTS
  • python3版本:3.6.8
  • pip 版本:pip 19.1.1 来自 /home/biggi/.local/lib/python3.6/site-packages/pip (python 3.6)

运行我的 python 脚本时出现错误

import requests 
ImportError: No module named requests

当我尝试:sudo pip install requests

The directory '/home/biggi/.cache/pip/http' or its parent directory is
not owned by the current user and the cache has been disabled. Please
check the permissions and owner of that directory. If executing pip
with sudo, you may want sudo's -H flag. The directory
'/home/biggi/.cache/pip' or its parent directory is not owned by the
current user and caching wheels has been disabled. check the
permissions and owner of that directory. If executing pip with sudo,
you may want sudo's -H flag. Requirement already satisfied: requests
in ./.local/lib/python2.7/site-packages Requirement already satisfied:
urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in
./.local/lib/python2.7/site-packages (from requests) Requirement
already satisfied: certifi>=2017.4.17 in
./.local/lib/python2.7/site-packages (from requests) Requirement
already satisfied: chardet<3.1.0,>=3.0.2 in
./.local/lib/python2.7/site-packages (from requests) Requirement
already satisfied: idna<2.9,>=2.5 in
./.local/lib/python2.7/site-packages (from requests)

答案1

使用sudo -H pip install requests解决了该问题:

收集请求 下载 https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl (57kB)100% |██████████████████████████████| 61kB 1.3MB/s 收集 urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1(来自请求)下载 https://files.pythonhosted.org/packages/e6/60/247f23a7121ae632d62811ba7f273d0e58972d75e58a94d329d51550a47d/urllib3-1.25.3-py2.py3-none-any.whl (150kB)100% |██████████████████████████████| 153kB 2.7MB/s 收集证书>=2017.4.17(来自请求)下载 https://files.pythonhosted.org/packages/69/1b/b853c7a9d4f6a6d00749e94eb6f3a041e342a885b87340b79c1ef73e3a78/certifi-2019.6.16-py2.py3-none-any.whl (157kB)100% |██████████████████████████████| 163kB 2.4MB/s 收集 chardet<3.1.0,>=3.0.2(来自请求)下载 https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB) 100% |██████████████████████████████| 143kB 3.0MB/s 要求已满足:/usr/lib/python2.7/dist-packages 中的 idna<2.9,>=2.5(来自请求)正在安装收集的软件包:urllib3、certifi、chardet、requests 成功安装 certifi-2019.6.16 chardet-3.0.4 request-2.22.0 urllib3-1.25.3

相关内容