Super User Asked by Matt Lyon on December 28, 2020
I am trying to run a python script, visible through the $env:PATH
environment variable, whilst using a python virtualenv
on Windows 10 PowerShell 5.1. e.g.
(venv) PS C:UsersmatthDev> script.py
Unfortunately, instead of running through the python the python interpreter available in the virtualenv
, it opens the file in the default program (in my case this is Visual Studio Code).
As per this stackexchange question and answer, i added ".py" to the PATHEXT
variable via the environment variable editor, and confirmed this was added by the following line.
(venv) PS C:UsersmatthDev> $env:PATHEXT
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.py;.CPL
Unfortunately this did not resolve my issue, as the script is still opened in Visual Studio Code, even after opening a new PowerShell instance.
As requested, below is the output of the $env:PATH
variable in its entirety.
(venv) PS C:UsersmatthDev> $env:PATH
C:UsersmatthDevvenv/Scripts;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1bin;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1libnvvp;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1extrasCUPTIlib64;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1include;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.0bin;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.0libnvvp;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.0extrasCUPTIlib64;C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.0include;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program FilesNVIDIA CorporationNVIDIA NvDLISR;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program FilesGitcmd;C:Program FilesNVIDIA CorporationNsight Compute 2020.2.1;C:msys64usrbin;C:Program FilesDockerDockerresourcesbin;C:ProgramDataDockerDesktopversion-bin;C:UsersmatthAppDataLocalProgramsPythonPython38Scripts;C:UsersmatthAppDataLocalProgramsPythonPython38;C:UsersmatthAppDataLocalMicrosoftWindowsApps;C:UsersmatthAppDataLocalProgramsMicrosoft VS Codebin
Is there something that I am missing?
I saw this problem mentioned in a related StackOverflow question yesterday.
Visual Studio Code apparently sets a number of file extension associations when it is installed, so the Windows association is taking priority over the shell's PATHEXT
. Unfortunately, the solution in the related question won't work for you, since you need the Python exe to be determine by the virtualenv
path, rather than "hard coded." And while Windows 10 makes it easy to change an association, removing it entirely is not as easy.
You could go through some hackery to remove the file extension association completely (probably via Registry edits, if you'd like), but the easiest way (according to this comment in Github) seems to be to uninstall VSCode, and reinstall with the "Register Code as an editor supported file types" option unchecked.
Correct answer by NotTheDr01ds on December 28, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP