Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Import the requests module (Python)

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
like image 940
Wesley Smith Avatar asked Aug 26 '26 02:08

Wesley Smith


1 Answers

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
like image 167
Engr Tanveer sultan Avatar answered Aug 28 '26 15:08

Engr Tanveer sultan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!