Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

venv isolation broken when debugging #22919

Open
sil-lnagel opened this issue Feb 15, 2024 · 2 comments
Open

venv isolation broken when debugging #22919

sil-lnagel opened this issue Feb 15, 2024 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team

Comments

@sil-lnagel
Copy link

sil-lnagel commented Feb 15, 2024

Type: Bug

Behaviour

Expected vs. Actual

When I activate a virtual environment I expect python to use packages from this virtual environment over globally installed packages.

If run the debugger with the vscode python extension on Ubuntu sys.path contains /usr/lib/python3/dist-packages in front of the venv packages. This causes global packages to be loaded.

If you add export PYTHONPATH="" to .zshrc this is not added to sys.path during debug. But if you modify the PYTHONPATH eg to add a src folder inside your launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Current File with Arguments",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "env": {
                "PYTHONPATH": "src"
            }
        }
    ]
}

it still shows up in sys.path

Steps to reproduce:

  1. Create venv
  2. Select venv in vscode
  3. Create launch.json file as above
  4. debug a python file and print sys.path
  5. Verify that /usr/lib/python3/dist-packages is in path before venv folders

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.18
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

User Settings


languageServer: "Pylance"

terminal
• activateEnvironment: false

Extension version: 2024.0.1
VS Code version: Code 1.86.2 (903b1e9d8990623e3d7da1df3d33db3e42d80eda, 2024-02-13T19:41:37.860Z)
OS version: Linux x64 6.2.0-39-generic
Modes:

A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:30899288
c4g48928:30535728
azure-dev_surveyone:30548225
vscrpc:30673769
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
pythontbext0:30879054
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
edj9j583:30958191
fegfb526:30961430
7j2b6412:30964151
ccp1r6:30958156

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 15, 2024
@irm-codebase
Copy link

I am having a similar issue with conda environments (#22918).
It seems like something is botched in the Python plugin.

@irm-codebase
Copy link

This is particularly annoying as I cannot debug properly unless I install the packages in the base environment.

@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants