0

I need to reference to requests in pip but it is already installed in python.

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

How can I change requests to pip?

  • Version of Ubuntu: 18.04.2 LTS
  • Version of python3: 3.6.8
  • Version of pip: pip 19.1.1 from /home/biggi/.local/lib/python3.6/site-packages/pip (python 3.6)

Running my python script I get the error

import requests 
ImportError: No module named requests

When I try to: 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)
3
  • someone who could help me with that? – Biggi Jul 11 '19 at 8:55
  • May be the module requests is installed in Python3 but not installed in Python2 and may be when you run your code, you run it in Python2. So try running your code with this command: python3 your_script.py – singrium Jul 13 '19 at 7:17
  • 1
    Please always use code formatting for posting terminal output, never blockquote. It destroys the original text structure and makes the information hard to read. Also edit your question to add more information, the answer section is for solutions only. Thank you. – Byte Commander Jul 13 '19 at 16:42
0

Using sudo -H pip install requests solved the problem:

Collecting requests Downloading https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl (57kB) 100% |████████████████████████████████| 61kB 1.3MB/s Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests) Downloading https://files.pythonhosted.org/packages/e6/60/247f23a7121ae632d62811ba7f273d0e58972d75e58a94d329d51550a47d/urllib3-1.25.3-py2.py3-none-any.whl (150kB) 100% |████████████████████████████████| 153kB 2.7MB/s Collecting certifi>=2017.4.17 (from requests) Downloading https://files.pythonhosted.org/packages/69/1b/b853c7a9d4f6a6d00749e94eb6f3a041e342a885b87340b79c1ef73e3a78/certifi-2019.6.16-py2.py3-none-any.whl (157kB) 100% |████████████████████████████████| 163kB 2.4MB/s Collecting chardet<3.1.0,>=3.0.2 (from requests) Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB) 100% |████████████████████████████████| 143kB 3.0MB/s Requirement already satisfied: idna<2.9,>=2.5 in /usr/lib/python2.7/dist-packages (from requests) Installing collected packages: urllib3, certifi, chardet, requests Successfully installed certifi-2019.6.16 chardet-3.0.4 requests-2.22.0 urllib3-1.25.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.