I want to use request module, but whenever I tried to import requests I got this message:
import "requests" could not be resolved from source Pylance
I already used pip to install the requests module, but I still receive this error message.
To solve unresolved import error in Python, set your Python path in your workspace settings. If you are working with Visual Studio Code and import any library, you will face this error: “unresolved import”. Then reload the VSCode, and it will fix that error.
Requests are not a built-in module (it doesn't come with the default python installation) in Python, you need to install it explicitly using the pip installer and then use it. If you are getting an error installing pip checkout pip: command not found to resolve the issue.
Have you made sure that you have installed the module by running
pip install requests
or
pip3 install requests
Additionally, you can tell VS Code to use different Python-interpreter in your system. I e.g. had the same problem, that VS Code code check gave me the warning, that I don't have the module requests installed, but when I run the python script it worked anyhow. That's why I believe that the python code check in VS Code can use different Python versions and related python packages than your system use when you run the code.
What helped me in order to get rid of the VS Code error message, choosing a different Python from here:
Try choosing the python interpreter manually. Choose view - select interpreter - enter interpreter path - choose the python folder - app then python application. This should work
I got the same error and solved it with this:
import pip._vendor.requests
If you are experiencing this problem on Windows, look at the installed extensions. I had this problem on both of my Windows machines. I noted that I had two extensions installed: Pylance & Intellisense (Pylance). Uninstalling Pylance and keeping intellisense (Pylance) solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With