4

I was trying out Python for the first time today and I ran into a problem. I want to import requests, but it shows an error in the code:

Error: Import "requests" could not be resolved from source Pylance(reportMissingModelSource) [4, 8]

I am using Visual Studio Code.

I've tried pip install requests and it looks good, but I'm still getting an error in my code.

When I do pip install requests:

(Removed locations except for first)

PS C:\Users\me\Desktop\python testing01> pip install requests
Requirement already satisfied: requests in c:\users\me\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (2.26.0)
Requirement already satisfied: idna<4,>=2.5 in
Requirement already satisfied: charset-normalizer~=2.0.0 in
Requirement already satisfied: urllib3<1.27,>=1.21.1 in
Requirement already satisfied: certifi>=2017.4.17 in
WARNING: You are using pip version 21.1.3; however, version 21.2.4 is available.
You should consider upgrading via the 'C:\Users\me\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe -m pip install --upgrade pip' command.

Relevant Python code:

import random

import requests
5

4 Answers 4

1

First of all, uninstall request by the following command:

pip uninstall requests

Then you have to install it again by the following command:

pip install requests

Now you have to import requests in the following way:

import requests
Sign up to request clarification or add additional context in comments.

Comments

0

Upgrade pip. Try:

pip install --upgrade pip

If your OS is Windows and if this command doesn't work, try:

python -m pip install --upgrade pip

Then try to install requests. It should work.

Comments

0

For me, I had to :

  1. Upgrade pip
    pip install --upgrade pip
  1. Uninstall requests
    pip uninstall requests
  1. Install requests
    pip install requests
  1. Then reboot VsCode

Comments

0

I had to install in the terminal and then it worked. Would not work when attempting in my IDE, (VS Code).

1 Comment

Sometimes your IDE runs a different Python environment then the one that your terminal defaults to, you may want to check what Python environment it's running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.