1

I am having a problem running my script in VSCode.

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 VSCode isn't using the correct interpreter that actually has the package installed.

Jacob Lee
  • 3,649
  • 2
  • 12
  • 30
  • Are you using a virtual environment? I remember having this issue with `requests` (not on MacOS nor with VSCode, but on Windows with plain-old IDLE); while I don't know what causes this behavior, I was able to solve it by creating a virtual environment and configuring my IDE (switched to PyCharm) to use that virtual environment interpreter. – Jacob Lee May 11 '21 at 22:29
  • I am not using a vm. Running on a 2019 MacBook Pro with the latest version of Big Sur. Thanks for the advice in case I use a VM in the furture – Frank Fiumara May 12 '21 at 04:39

3 Answers3

2

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.

Jacob Walls
  • 698
  • 2
  • 13
1

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

  • Open Command Palette in vscode 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").

Chuu
  • 166
  • 7
0

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.

Robin Duong
  • 41
  • 1
  • 9