Frank Fiumara
Frank Fiumara

Reputation: 120

"ModuleNotFoundError: No Module Named 'requests'" with Visual Studio Code on macOS

I am having a problem running my script in Visual Studio Code.

I have tried the following:

  1. Reinstalling requests through pip, easy_install, and sudo pip
  2. Importing requests directly in the Python interpreter (which worked)

This leads me to believe that Visual Studio Code isn't using the correct interpreter that actually has the package installed.

Upvotes: 2

Views: 6508

Answers (3)

Chuu
Chuu

Reputation: 196

I think yours is a Python environment problem. To check whether it's Python environment or not, you can use which python (or which python3 if you use Python 3) command in your both Visual Studio Code terminal and Mac terminal. If you see different python path, then your Visual Studio Code is using different python environment. You can change the Python interpreter in Visual Studio Code to have same environment as your Mac terminal.

  • Open Command Palette in Visual Studio Code with + + P
  • Type "Python: Select Interpreter"

Then, choose the same environment as your Mac terminal (if you want the same one, you can choose the same Python environment path as Mac terminal that you get with "which python" or "which python3").

Upvotes: 1

Robin Duong
Robin Duong

Reputation: 71

You may be able to find a solution here: ImportError: No module named requests

You haven't mentioned using different versions in your commands. It's possible you need to use pip3 instead of pip, or python3 instead of python.

Upvotes: 0

Jacob Walls
Jacob Walls

Reputation: 861

You can choose your interpreter in VS Code in several ways. One of them is by clicking the tab in the bottom toolbar (lower-left) which might say "Python 3.9.4 (64-bit)", upon which you will be able to select from a menu of choices, e.g. /usr/bin/python3 or a conda or brew installation, etc.

Upvotes: 2

Related Questions