No Module named 'requests'

Hi all, I am hoping for a little help. In Visual Studio I am running some code and am getting an error with import requests, when I run the code, it tells me no module named 'requests'. However, if I run the same code in Jupyter notebook it works fine. I have run pip install requests in my environment and it is already satisfied. Any ideas on why it would work in one notebook vs. the other?

Best Answer

  • 0 Like Reply Share

    More...


    Initially I used pip install requests within VS. The request came back, all requirements satisfied. I restarted VS with a new terminal and tried pip install requests again. This time it installed requests and then everything worked fine.

Answers

  • Hi @milan.hedstrom

    I have never used Visual Studio but from your question, it seems to be a Visual Studio environment issue.

    So I google "visual studio pip install python" and I got this url,

    https://docs.microsoft.com/en-us/visualstudio/python/tutorial-working-with-python-in-visual-studio-step-05-installing-packages?view=vs-2019

    Hope this help.

  • Hi @milan.hedstrom

    I had similar issues myself when I was trying out VS and for me, it was as explained in the link above - my VS and Jupyter were using different Python environments.

    the missing package was installed in the Jupyter used env but not in the VS env

  • Thanks, I had that thought as well. I then opened a terminal within VS and did pip install requests and it comes up as already satisfied...

  • it is working now, I have figured it out. Many thanks for the replies.

  • Initially I used pip install requests within VS. The request came back, all requirements satisfied. I restarted VS with a new terminal and tried pip install requests again. This time it installed requests and then everything worked fine.

  • The "ImportError: No module named requests" error occurs when you try to import the "requests" module in Python, but it's not installed in your environment. To fix this, you should install the "requests" library using pip, a package manager for Python. Open your command prompt or terminal and run the command "pip install requests." This will download and install the "requests" module, allowing you to use it in your Python scripts. Ensure that pip is properly installed and configured in your Python environment before running the installation command.