skip to Main Content

I’m using Python 3.12.3, latest vscode and from a (Windows) terminal I can set up and run venv fine. If I am in vscode, go to th the terminal window and run all my commands (xScriptsactivate.bat) it switches fine and uses the virtual environment.

However, it is failing within vscode in both ways I know how:

  1. If I start vscode in a folder where there is a venv it says ‘I can see you have a venv do you want to switch to it’. When I select yes it generates no error but it has not switched and everything still goes/uses global space

  2. If I run the vscode command ‘create virtual environment’ (the way I want to use venv in vscode), select venv as the option it falls over as follows log. Note, that pip works just fine as from the same terminal window in vscode I can manually upgrade PIP and it is actually on the latest version already prior to this script running

So it is only when vscode is running the commands itself is things failing.

Any thoughts appreciated.

2024-10-29 14:02:12.434 [info] Selected workspace c:DATA_NODRIVEProjectstestproject for creating virtual environment.
2024-10-29 14:02:12.439 [info] Starting Environment refresh
2024-10-29 14:02:12.440 [info] Searching for windows registry interpreters
2024-10-29 14:02:12.440 [info] Searching windows known paths locator
2024-10-29 14:02:12.441 [info] Searching for pyenv environments
2024-10-29 14:02:12.441 [info] Searching for conda environments
2024-10-29 14:02:12.441 [info] Searching for global virtual environments
2024-10-29 14:02:12.441 [info] Searching for custom virtual environments
2024-10-29 14:02:12.442 [info] Searching for windows store envs
2024-10-29 14:02:12.448 [info] > hatch env show --json
2024-10-29 14:02:12.448 [info] cwd: .
2024-10-29 14:02:12.453 [info] pyenv is not installed
2024-10-29 14:02:12.453 [info] Finished searching for pyenv environments: 13 milliseconds
2024-10-29 14:02:12.460 [info] Finished searching for custom virtual envs: 20 milliseconds
2024-10-29 14:02:12.460 [info] Finished searching for windows store envs: 20 milliseconds
2024-10-29 14:02:12.463 [info] Finished searching for global virtual envs: 23 milliseconds
2024-10-29 14:02:12.483 [info] > C:DATA_NODRIVEapplicationspython312python.exe -I ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesget_output_via_markers.py ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesinterpreterInfo.py
2024-10-29 14:02:12.505 [info] Finished searching for windows registry interpreters: 54 milliseconds
2024-10-29 14:02:12.505 [info] > C:DATA_NODRIVEapplicationspython310python.exe -I ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesget_output_via_markers.py ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesinterpreterInfo.py
2024-10-29 14:02:12.514 [info] Finished searching windows known paths locator: 76 milliseconds
2024-10-29 14:02:12.514 [info] Environments refresh paths discovered (event): 76 milliseconds
2024-10-29 14:02:12.514 [info] Environments refresh paths discovered: 76 milliseconds
2024-10-29 14:02:12.628 [info] > C:DATA_NODRIVEapplicationspythonpython.exe -I ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesget_output_via_markers.py ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesinterpreterInfo.py
2024-10-29 14:02:12.718 [info] Environments refresh finished (event): 280 milliseconds
2024-10-29 14:02:12.740 [info] Environment refresh took 304 milliseconds
2024-10-29 14:02:12.774 [warning] Identifier for virt-virtualenv failed to identify c:DATA_NODRIVEProjectstestprojectneilScriptspython.exe [Error: ENOENT: no such file or directory, scandir 'c:DATA_NODRIVEProjectstestprojectneilScripts'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'scandir',
  path: 'c:\DATA_NODRIVE\Projects\testproject\neil\Scripts'
}

2024-10-29 14:02:12.795 [info] > .neilScriptspython.exe -I ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesget_output_via_markers.py ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesinterpreterInfo.py
2024-10-29 14:02:12.837 [error] Error: Command failed: c:DATA_NODRIVEProjectstestprojectneilScriptspython.exe -I c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesget_output_via_markers.py c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesinterpreterInfo.py
The system cannot find the path specified.

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at ChildProcess.exithandler (node:child_process:423:12)
    at ChildProcess.emit (node:events:531:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  code: 1,
  killed: false,
  signal: null,
  cmd: 'c:\DATA_NODRIVE\Projects\testproject\neil\Scripts\python.exe -I c:\Users\neil\.vscode\extensions\ms-python.python-2024.16.1-win32-x64\python_files\get_output_via_markers.py c:\Users\neil\.vscode\extensions\ms-python.python-2024.16.1-win32-x64\python_files\interpreterInfo.py'
}
2024-10-29 14:02:13.927 [info] Selected interpreter C:DATA_NODRIVEapplicationspython312python.exe for creating virtual environment.
2024-10-29 14:02:14.018 [info] Running Env creation script:  [
  'C:\DATA_NODRIVE\applications\python312\python.exe',
  'c:\Users\neil\.vscode\extensions\ms-python.python-2024.16.1-win32-x64\python_files\create_venv.py',
  '--git-ignore'
]
2024-10-29 14:02:14.018 [info] > C:DATA_NODRIVEapplicationspython312python.exe ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filescreate_venv.py --git-ignore
2024-10-29 14:02:14.018 [info] cwd: .
2024-10-29 14:02:14.179 [info] Running: C:DATA_NODRIVEapplicationspython312python.exe -m venv .venv
2024-10-29 14:02:14.847 [info] > .neilScriptspython.exe -I ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesget_output_via_markers.py ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesinterpreterInfo.py
2024-10-29 14:02:14.897 [error] Error: Command failed: c:DATA_NODRIVEProjectstestprojectneilScriptspython.exe -I c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesget_output_via_markers.py c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesinterpreterInfo.py
The system cannot find the path specified.

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at ChildProcess.exithandler (node:child_process:423:12)
    at ChildProcess.emit (node:events:531:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  code: 1,
  killed: false,
  signal: null,
  cmd: 'c:\DATA_NODRIVE\Projects\testproject\neil\Scripts\python.exe -I c:\Users\neil\.vscode\extensions\ms-python.python-2024.16.1-win32-x64\python_files\get_output_via_markers.py c:\Users\neil\.vscode\extensions\ms-python.python-2024.16.1-win32-x64\python_files\interpreterInfo.py'
}
2024-10-29 14:02:14.937 [warning] Identifier for virt-virtualenv failed to identify c:DATA_NODRIVEProjectstestprojectneilScriptspython.exe [Error: ENOENT: no such file or directory, scandir 'c:DATA_NODRIVEProjectstestprojectneilScripts'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'scandir',
  path: 'c:\DATA_NODRIVE\Projects\testproject\neil\Scripts'
}

2024-10-29 14:02:15.389 [info] > ..venvScriptspython.exe -I ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesget_output_via_markers.py ~.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filesinterpreterInfo.py
2024-10-29 14:02:15.390 [info] Environments refresh paths discovered: 23 milliseconds
2024-10-29 14:02:15.566 [info] Environments refresh finished (event): 199 milliseconds
2024-10-29 14:02:23.410 [info] CREATED_VENV:c:DATA_NODRIVEProjectstestproject.venvScriptspython.exe
2024-10-29 14:02:23.411 [info] Creating: c:DATA_NODRIVEProjectstestproject.venv.gitignore
CREATE_VENV.UPGRADING_PIP
Running: c:DATA_NODRIVEProjectstestproject.venvScriptspython.exe -m pip install --upgrade pip
2024-10-29 14:02:24.071 [info] Requirement already satisfied: pip in c:data_nodriveprojectstestproject.venvlibsite-packages (24.0)
2024-10-29 14:02:24.561 [info] Collecting pip
2024-10-29 14:02:24.578 [info]   Using cached pip-24.3.1-py3-none-any.whl.metadata (3.7 kB)
2024-10-29 14:02:24.610 [info] Using cached pip-24.3.1-py3-none-any.whl (1.8 MB)
2024-10-29 14:02:24.693 [info] Installing collected packages: pip
2024-10-29 14:02:24.694 [info]   Attempting uninstall: pip
2024-10-29 14:02:24.699 [info]     Found existing installation: pip 24.0
2024-10-29 14:02:24.912 [info]     Uninstalling pip-24.0:
2024-10-29 14:02:25.843 [info] ERROR: Could not install packages due to an OSError: [WinError 32] The process cannot access the file because it is being used by another process: 'c:\data_nodrive\projects\testproject\.venv\lib\site-packages\pip\_internal\resolution'
Check the permissions.
2024-10-29 14:02:25.849 [info] WARNING: Ignoring invalid distribution ~ip (c:DATA_NODRIVEProjectstestproject.venvLibsite-packages)
2024-10-29 14:02:25.874 [info] WARNING: Ignoring invalid distribution ~ip (c:DATA_NODRIVEProjectstestproject.venvLibsite-packages)
2024-10-29 14:02:25.996 [info] Traceback (most recent call last):
  File "c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filescreate_venv.py", line 96, in run_process
2024-10-29 14:02:25.997 [info]     subprocess.run(args, cwd=os.getcwd(), check=True)  # noqa: PTH109
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:DATA_NODRIVEapplicationspython312Libsubprocess.py", line 571, in run
2024-10-29 14:02:26.024 [info]     raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['c:\DATA_NODRIVE\Projects\testproject\.venv\Scripts\python.exe', '-m', 'pip', 'install', '--upgrade', 'pip']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filescreate_venv.py", line 262, in <module>
    main(sys.argv[1:])
  File "c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filescreate_venv.py", line 245, in main
    upgrade_pip(venv_path)
  File "c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filescreate_venv.py", line 134, in upgrade_pip
    run_process(
  File "c:Usersneil.vscodeextensionsms-python.python-2024.16.1-win32-x64python_filescreate_venv.py", line 98, in run_process
    raise VenvError(error_message) from exc
VenvError: CREATE_VENV.UPGRADE_PIP_FAILED
2024-10-29 14:02:26.039 [error] Error while running venv creation script:  CREATE_VENV.UPGRADE_PIP_FAILED
2024-10-29 14:02:26.039 [error] CREATE_VENV.UPGRADE_PIP_FAILED

2

Answers


  1. You say, everything still goes/uses global space, but can you elaborate what you mean by everything… e.g. debugging? pylance?

    Have you tried deleting your existing virtual environments and reloading vs-code? This tends to work for me.

    This would be a comment, but I’m not allowed…

    Login or Signup to reply.
  2. From what I see is all these errors are related to a not-existing Python interpreter. You need to select another interpreter with Python: Select Interpreter command and select a working one.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search