microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

Unable to select any virtualenv other than `.venv` in the workspace root #23177

Closed albgus closed 5 months ago

albgus commented 7 months ago

Type: Bug

Behaviour

Expected vs. Actual

Selecting a virtualenv should activate the selected virtualenv. Instead, exclusively the $WORKSPACE/.venv environment is attempted to be used. Selecing another virtualenv, for example from .virtualenvs with either activate $WORKSPACE/.venv instead, or fail to activate any virtualenv.

Steps to reproduce:

  1. Create a virtualenv anywhere except $WORKSPACE/.venv
  2. Run the Python: Select interpreter command.

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` 2024-04-04 10:31:04.666 [warning] Failed to check if /Users/XXXX/Code/misc/.venv/bin/python is an executable [Error: ENOENT: no such file or directory, lstat '/Users/XXXX/Code/misc/.venv/bin/python'] { errno: -2, code: 'ENOENT', syscall: 'lstat', path: '/Users/XXXX/Code/misc/.venv/bin/python' } 2024-04-04 10:31:04.668 [warning] Identifier for virt-virtualenv failed to identify /Users/XXXX/Code/misc/.venv/bin/python [Error: ENOENT: no such file or directory, scandir '/Users/XXXX/Code/misc/.venv/bin'] { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/Users/XXXX/Code/misc/.venv/bin' } # Note that at this point I create the .venv in the workspace root, then try to select a virtualenv from ~/.virtualenvs again, yet it seems to activate the virtualenv in .venv instead. 2024-04-04 10:31:35.158 [info] Discover tests for workspace name: misc - uri: /Users/XXXX/Code/misc/kube-instance-refresh/main.py 2024-04-04 10:31:44.632 [info] > ~/Code/misc/.venv/bin/python -I ~/.vscode/extensions/ms-python.python-2024.2.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.2.1/pythonFiles/interpreterInfo.py 2024-04-04 10:31:51.412 [info] Python interpreter path: ~/Code/misc/.venv/bin/python ```

User Settings

``` Multiroot scenario, following user settings may not apply: venvPath: "" languageServer: "Pylance" ```

Extension version: 2024.2.1 VS Code version: Code 1.87.2 (863d2581ecda6849923a2118d93a088b0745d9d6, 2024-03-08T15:21:31.043Z) OS version: Darwin x64 23.3.0 Modes:

anthonykim1 commented 7 months ago

Hello @albgus Thanks for filing the issue. Can you specify what venvPath: "<placeholder>" you are using specifically? Also it would be beneficial for you to explain $WORKSPACE/.venv

ibdafna commented 7 months ago

Seeing the same issue. It's actually also hurting Jupyter kernel discovery for Python kernels. If the current Python extension is installed then I can't see any Python kernels under Jupyter. Same errors as the user is describing above. I think what he means by $WORKSPACE is essentially the root folder where VS Code is opened from.

  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: '/root/notebooks/.venv/bin/python'
}
2024-04-16 22:01:32.978 [warning] Identifier for virt-virtualenv failed to identify /root/notebooks/.venv/bin/python [Error: ENOENT: no such file or directory, scandir '/root/notebooks/.venv/bin'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: '/root/notebooks/.venv/bin'
}
2024-04-16 22:01:33.070 [info] > ./.venv/bin/python -I ~/.vscode-server/extensions/ms-python.python-2024.4.1/python_files/get_output_via_markers.py ~/.vscode-server/extensions/ms-python.python-2024.4.1/python_files/interpreterInfo.py
2024-04-16 22:01:33.140 [info] > pyenv which python
2024-04-16 22:01:33.140 [info] cwd: .
2024-04-16 22:01:33.182 [error] [Error: Command failed: /root/notebooks/.venv/bin/python -I /root/.vscode-server/extensions/ms-python.python-2024.4.1/python_files/get_output_via_markers.py /root/.vscode-server/extensions/ms-python.python-2024.4.1/python_files/interpreterInfo.py
/bin/sh: line 1: /root/notebooks/.venv/bin/python: No such file or directory

    at ChildProcess.exithandler (node:child_process:422:12)
    at ChildProcess.emit (node:events:529:35)
    at maybeClose (node:internal/child_process:1098:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:517:28)
    at Pipe.<anonymous> (node:net:350:12)] {
  code: 127,
  killed: false,
  signal: null,
  cmd: '/root/notebooks/.venv/bin/python -I /root/.vscode-server/extensions/ms-python.python-2024.4.1/python_files/get_output_via_markers.py /root/.vscode-server/extensions/ms-python.python-2024.4.1/python_files/interpreterInfo.py'
}
2024-04-16 22:01:33.534 [warning] Failed to check if /root/notebooks/.venv/bin/python is an executable [Error: ENOENT: no such file or directory, lstat '/root/notebooks/.venv/bin/python'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: '/root/notebooks/.venv/bin/python'
}
2024-04-16 22:01:33.536 [warning] Failed to check if /root/notebooks/.venv/bin/python is an executable [Error: ENOENT: no such file or directory, lstat '/root/notebooks/.venv/bin/python'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: '/root/notebooks/.venv/bin/python'
}
2024-04-16 22:01:33.585 [warning] Identifier for virt-virtualenv failed to identify /root/notebooks/.venv/bin/python [Error: ENOENT: no such file or directory, scandir '/root/notebooks/.venv/bin'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: '/root/notebooks/.venv/bin'
}
2024-04-16 22:01:33.588 [warning] Identifier for virt-virtualenv failed to identify /root/notebooks/.venv/bin/python [Error: ENOENT: no such file or directory, scandir '/root/notebooks/.venv/bin'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: '/root/notebooks/.venv/bin'
}

I don't have any setting for venvPath. I also don't have a .venv folder under /root/notebooks.

anthonykim1 commented 6 months ago

@karthiknadig Do we officially support .virtualenvs? (https://virtualenv.pypa.io/en/latest/)

anthonykim1 commented 6 months ago

@albgus @ibdafna Does downgrading to previous version(s) resolve the issue? Feel free to try from most recent to historically earliest. It can be done by clicking on the dropdown like in the screenshot. It should show lists of previous versions of the Python extension:

Screenshot 2024-04-28 at 10 54 56 PM
github-actions[bot] commented 5 months ago

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.

Happy Coding!