Powershell and python executables

I’m trying to run simple python scripts with PowerShell. I can run my scripts in .cmd without a hitch. The path looks proper. I opened PowerShell in admin mode as well and it’s still not working.
Researching the web, it seems that MicroSoft disables the functionality of running python with PowerShell?
I’m on PS 7.2 and python 3.11

Thanks,

I solved it. Looks like you need to type python and then the file name. Thanks.

You can run scripts (python, powershell, etc) from a PS prompt by using the “.\” syntax, just like “./” from a Linux shell.

PS C:\pyprograms> .\lanscan2

If .py files are correctly associated with the “Python.File” progid, then you should be able to run Python scripts directly in the shell if they’re in any directory in the PATH environment variable. A script in the current directory (“.”) has to be referenced explicitly, e.g. .\spam.py.

PowerShell misuses the PATHEXT environment variable, however. In CMD, PATHEXT has always been just a list of extensions to try appending when searching PATH for a file, and it has nothing to do with how or whether files are allowed to be executed. PowerShell, in contrast, requires a file extension to be in PATHEXT in order to execute the file type normally in the current console session. So make sure that “.PY” is included in PATHEXT.

1 Like