Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using venv - VS Code debugging doesn't see all pip installed packages

Running VS Code on Windows with Python 3.7.2 32bit with venv environments. I've searched and searched and either there's something I'm doing wrong, or VS Code won't do what I want it to do.

The VS Code debugger running under "Python: Current File (Integrated Terminal)" doesn't find packages installed using pip install inside my (env). In fact, it doesn't appear that the packages are being installed in the virtual environment at all.

Whenever I try to debug a single py file the debugger tells me it cannot find the package I installed using pip. I installed the packages inside the venv (env), or so I thought. However, running pip list with the (env) active shows the same list as when it's deactivated.

I've noticed that running pip install while the (env) is active doesn't always result in the package being installed inside my environment. pip list will show it, but pip show shows it in Python's appdata\local\programs\python\python37-32\lib\site-packages.

I'm creating the environments using python -m venv env inside the vs code terminal (either python shell or git bash shell). It shows the (env) as active, so I'm not sure what I'm doing.

I have not changed the launch.json config: { "name": "Python: Current File (Integrated Terminal)", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal" }

VS Code shows I'm using the correct venv interpreter:

Python 3.7.2 32-bit ('env': venv)

Running the script directly in the VS Code terminal python script.py works correctly every time.

Manually copying packages from:

appdata\local\programs\python\python37-32\lib\site-packages

to

env\lib\site-packages

allows the debugger to work without errors. This is great, and it's a workaround, but it appears the issue is more with my venv not actually acting like a venv.

I don't see any issue with venv on my linux machines, but they're mostly headless so I'm not running VS Code.

Any idea what I'm missing? Thanks for any help.

like image 560
Jon S. Avatar asked Feb 11 '19 15:02

Jon S.


People also ask

How do I list all packages in VENV?

You can list only packages in the virtualenv by pip freeze --local or pip list --local . This option works irrespective of whether you have global site packages visible in the virtualenv .

How do you see all pip installed packages?

If you want to list all the Python packages installed in an environment, pip list command is what you are looking for. The command will return all the packages installed, along with their specific version and location. If a package is installed from a remote host (for example PyPI or Nexus) the location will be empty.

Why Python interpreter is not showing in VS Code?

If VS Code doesn't automatically locate the interpreter you're looking for, refer to Environments - Manually specify an interpreter. You can configure the Python extension through settings. Learn more in the Python Settings reference.


1 Answers

Have you tried adding:

"justmycode": false

in the debug configuration? It defaults to true, and will only let you debug your own files. Here my config:

    {
        "name": "Python: Current File (Integrated Terminal)",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "justMyCode": false
    }
like image 99
Tom Avatar answered Jan 03 '23 01:01

Tom