AnswerBun.com

Windows PowerShell opens python scripts in default program

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?

Super User Asked by Matt Lyon on December 28, 2020

1 Answers

One Answer

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

Add your own answers!

Related Questions

Windows C drive got mismatched

0  Asked on November 3, 2021 by md-fahad

         

Converting text to rows in a huge dataset

1  Asked on November 3, 2021 by l-t

 

Microsoft mystery MIB or Who has MSFT.MIB

1  Asked on March 11, 2021 by hkc

   

Put a command in history without executing it

4  Asked on March 3, 2021 by dan-hulme

 

Monitor Requires Power Cycle after Restart or Power Up

2  Asked on March 3, 2021 by gorchestopher-h

   

Why gmail reimports old mail again?

1  Asked on February 27, 2021 by wojciech-ptak

     

Cmd script does not work properly

2  Asked on February 26, 2021 by alphainc

         

Windows file content indexation via script

0  Asked on February 26, 2021 by laniakea

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.