VScode debugger cannot import modules from site-packages

2.1k Views Asked by At

I have C:\Users\user\AppData\Roaming\Python\Python37\site-packages directory in sys.path

And while I run code via cmd it works fine.

However, when i try run it via vscode debugger, I get this:

No module named request

So, how can I fix this?

1

There are 1 best solutions below

1
On

According to your description, it is recommended that you could try the following methods:

  1. Check the python interpreter for the current VSCode.

    When running python files in the cmd window, the system uses the python set by the environment variable.

    About it can run in cmd, but not in VSCode.This will happen if the Python interpreter used in VSCode is different from the cmd. Reference:python-interpreter.

  2. Try using pip to install the required module again. Use 'pip --version'(Linux and Mac:'pip -v') at the terminal to check whether the version of pip comes from the current interpreter.Use 'pip install <modules name>' to install it. Then, check whether the module is in the list by 'pip list'.

  3. Attempt to reload VSCode.

Above, I could import the required modules from similar locations. My environment:python:3.8.3; VSCode:1.47.2; Win10.

Update:

launch.json:

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python: Current File",
            "type": "python",  
            "request": "launch",
            "program": "${file}",
             "console": "integratedTerminal"   
        }
    ]
}