In PowerShell, Get-Command python | fl * will tell you which Python executable it's finding and show you details about where it is.

  1. You can check Settings -> Apps and Features, or Control Panel -> Programs and Features. They will show you distinct versions of Python you installed, but that might not be enough if Python is installed as part of some other toolkit or program.
  2. If Python 2.7.11 is there, select it and click uninstall. If it's not there, see if you can tell what it's installed with, from the output of Get-Command earlier, and decide if you want to remove that.
  3. How PowerShell chooses what to run when you type a command is explained in help about_Command_Precedence, and is:
    1. Alias
    2. Function
    3. Cmdlet
    4. Native Windows commands

At the point of "Native Windows commands", it goes to the PATH environment variable, a semi-colon separated list of path names, which get searched in order, looking for a matching executable file.

You can see the folders with:

$Env:PATH -split ';'

And you can watch PowerShell identify what to run for 'python' with the command

Trace-Command –Name CommandDiscovery –Expression {get-command python} -PSHost

So, to make Python 2.7.13 the one to launch, you could:

  • make it the only Python version available.
  • move its folder to the front of the PATH list, ahead of any other version. See: What are path and other environment variables, and how can I set or use them - question on SuperUser.com
  • make a batch file to launch it called python.bat in a folder in the PATH ahead of other versions.
  • make an alias (in your PS Profile) named python to launch the one you want (New-Alias -name python -Value C:\Python27\python.exe , etc).
Answer from TessellatingHeckler on Stack Overflow
Top answer
1 of 3
34

In PowerShell, Get-Command python | fl * will tell you which Python executable it's finding and show you details about where it is.

  1. You can check Settings -> Apps and Features, or Control Panel -> Programs and Features. They will show you distinct versions of Python you installed, but that might not be enough if Python is installed as part of some other toolkit or program.
  2. If Python 2.7.11 is there, select it and click uninstall. If it's not there, see if you can tell what it's installed with, from the output of Get-Command earlier, and decide if you want to remove that.
  3. How PowerShell chooses what to run when you type a command is explained in help about_Command_Precedence, and is:
    1. Alias
    2. Function
    3. Cmdlet
    4. Native Windows commands

At the point of "Native Windows commands", it goes to the PATH environment variable, a semi-colon separated list of path names, which get searched in order, looking for a matching executable file.

You can see the folders with:

$Env:PATH -split ';'

And you can watch PowerShell identify what to run for 'python' with the command

Trace-Command –Name CommandDiscovery –Expression {get-command python} -PSHost

So, to make Python 2.7.13 the one to launch, you could:

  • make it the only Python version available.
  • move its folder to the front of the PATH list, ahead of any other version. See: What are path and other environment variables, and how can I set or use them - question on SuperUser.com
  • make a batch file to launch it called python.bat in a folder in the PATH ahead of other versions.
  • make an alias (in your PS Profile) named python to launch the one you want (New-Alias -name python -Value C:\Python27\python.exe , etc).
2 of 3
1

This was a question about python 2.7, but probably it will be useful to give an answer for the versions above 3.3 too:

Previously, multiple versions (also environments, also they are specific folders) of python on the same system was rare, and placing the only available python.exe directly in PATH was acceptable. Currently, multiple installed python versions will conflict and override each other if simply placed that way.
After 3.3 a python launcher was introduced which detects and activates one of the installed versions automatically. It is supposed to be placed in PATH instead of any python executable.

So in this modern situation, Get-Command python | fl * may give you nothing or nothing helpful.
And to run scripts or to get available versions, use launcher:

  • ensure you have it:
    try Get-Command py command from the PowerShell. If launcher is missing, it can be installed with the official installer. There is a separate checkbox for the launcher which is enabled by default.
  • if install is correct, command py --list-paths will give a summary on the installed versions, and supposed way to run scripts is not previous python main.py, but commands like py main.py or py -3.5 main.py. Run py --help for more info.

Additional confirmation that intended way changed.

Just to give an idea, launcher is not the only way to activate, this also can be done by a simple command.
For example, there is a version under D:\python_install\python.exe. But it's not in the PATH and python command correctly ends with not found error or opens Windows Store. An additional command in cmd or bat SET PATH=D:\python_install\;%PATH% or PowerShell $env:Path = "D:\python_install\;" + $env:Path temporarily activates that specific version, and python will work as previously during that specific run.

🌐
Full Stack Python
fullstackpython.com › powershell.html
PowerShell - Full Stack Python
PowerShell is an implementation of the shell concept and is often used during Python software development on Windows.
🌐
ADMIN Magazine
admin-magazine.com › Archive › 2017 › 41 › Comparing-PowerShell-and-Python
PowerShell vs. Python » ADMIN Magazine
However, PowerShell is not the only scripting language – Python is also a popular option. In this article, we compare the two languages and examine possible usage scenarios on Windows, Linux, and Mac OS. We'll start with Python. Linux admins and users have probably used Python, even if only to run a .py script on their computers. Python, which was developed in the spirit of free software, is available free of charge as source code and in binary form, together with the standard library [1].
🌐
Reddit
reddit.com › r/powershell › python vs powershell?
r/PowerShell on Reddit: Python vs PowerShell?
March 7, 2024 -

I'm a .Net stack developer and know PS very well but I've barely used Python and it seems like Python has been constantly moving towards being the mainstream language for a myriad of things.

I see Microsoft adding it to Excel, more Azure functionality, it's #1 for AI/machine learning, data analysis, more dominate in web apps, and seemingly other cross platform uses.

I've been hesitant to jump into the Python world, but am I wrong for thinking more of my time should be invested learning Python over PowerShell for non-Windows specific uses?

Or how do people familiar with both PS & Python feel about learning the languages and their place in the ecosystem?

🌐
Adam the Automator
adamtheautomator.com › powershell-vs-python
PowerShell vs. Python: A Battle for the Ages
May 22, 2021 - Both PowerShell and Python reuse code by the means of modules. Modules can be potentially reused later in other programs, or you can directly import modules created by other programmers. Both languages have a large library of modules which you can easily use in your scripts.
Top answer
1 of 16
3

If Python feels more natural to you and helps you learn valuable skills, it’s perfectly fine to use it for Windows scripting. While PowerShell is often more concise for OS-related tasks and is natively integrated into Windows, Python offers greater flexibility, cross-platform compatibility, and broader use cases beyond scripting. You may occasionally need PowerShell for deep Windows integration (e.g., registry edits, GPO management), but for general automation, Python is a solid choice, especially if it aligns with your learning goals and future career prospects.

2 of 16
8

Hi everyone,

I wanted advices on which language to use for scripting purposes on Windows. I know it depends a lot on the script that I want to make but generally speaking, is Python an OK language to script in for basic OS related tasks or should I go with Powershell ?

I actually did write a basic script which allows me to clear my MS Teams cache on startup in both languages and even though Powershell is way shorter I still prefer the way Python does it. A big plus for me is that by writing scripts in Python I am learning more about it and since you can use it for various programming purposes (other than scripting) I will be gaining some really valuable skills by doing so…

I understand Python a lot more easily than Powershell at the moment and I know that Python is not (yet) integrated in Windows by default but it feels way more natural to me so I am thinking about just doing every scripting tasks with it. Since most of the companies out there are using Python in their prod env, is it OK to use it instead of traditionnal Powershell ?

Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1332563 › windows-powershell-starts-old-python
Windows powershell starts old python - Microsoft Q&A
July 18, 2023 - Check File Associations: On Windows, ... with .py files. You can check this in the "Default apps" settings or use the ftype command in PowerShell:...
🌐
PyPI
pypi.org › project › pypsrp
pypsrp - Python PowerShell Remoting Protocol Client library
pypsrp is a Python client for the PowerShell Remoting Protocol (PSRP) and Windows Remote Management (WinRM) service.
      » pip install pypsrp
    
Published   Feb 21, 2022
Version   0.8.1
🌐
Jamie Phillips
phillipsj.net › posts › executing-powershell-from-python
Executing PowerShell from Python • Jamie Phillips
October 26, 2020 - You will not need any external libraries since we use one of the many great libraries that ship out of the box with Python. All we need is to create a file call ps.py, and then we can import the subprocess module. ... Now we can make our run method that we will use to execute our PowerShell command.
🌐
Microsoft Community Hub
techcommunity.microsoft.com › microsoft community hub › communities › topics › itops talk › itops talk blog
The Syntax Difference Between Python and PowerShell
October 7, 2020 - Having only dabbled in both, I am not an authority on either to share my opinion. From a fact's perspective, PowerShell provides a shell scripting environment whereas Python is an interpreted high-level programming language.
🌐
Reddit
reddit.com › r/learnpython › powershell to python command/function equivalents?
r/learnpython on Reddit: PowerShell to Python command/function equivalents?
October 26, 2023 -

Stupid question - but I have a pretty solid grasp on PowerShell - is there like a list out there of Python vs PowerShell equivalents?

So for this is what I have:

Get-Member Equivalent - dir(object)
Get-Member Equivalent - type(object)
Get-Help Equivalent - help(object)

🌐
Reddit
reddit.com › r/learnpython › command prompt or powershell for python 3
r/learnpython on Reddit: Command Prompt or Powershell for Python 3
August 5, 2022 -

I just started learning Python 3 recently and the course I'm learning it from "Python for Everybody by Dr. Charles Severace". In the lessons, he uses Command Prompt to run his code. I've also heard that Powershell is basically the same thing as CP, just that it can do more. The question is, should I switch over to PS now, or does it not matter when just as long as I get to know how to use both eventually?

🌐
Quora
quora.com › Why-wont-Python-work-in-PowerShell-for-me
Why won't Python work in PowerShell for me? - Quora
Multiple Python installations: pip might install to a different interpreter than the one you run. Always use the same launcher: python -m pip install ... or py -3 -m pip install .... Virtual environments: activate venv with .\venv\Scripts\Activate (PowerShell) or use the full path to the venv’s python.
🌐
MiniTool Partition Wizard
partitionwizard.com › home › partition magic › check python version on windows/mac/linux [guide]
Check Python Version on Windows/Mac/Linux [Guide] - MiniTool Partition Wizard
July 19, 2023 - How to check Python version? Well, this post tells you how to perform a Python version check on operating systems like Windows, mac, and Linux respectively. Step 1: Right-click on the Windows icon on the desktop and click Windows PowerShell.
🌐
Advanced Installer
advancedinstaller.com › execute-python-script-through-powershell.html
Executing Python Scripts through PowerShell: A Step-by-Step Guide
February 22, 2024 - In your Python script, use the sys module to access command-line arguments: ... This will output: Received argument: your_argument. Run the following command in PowerShell to locate the Python executable:
🌐
Microsoft
devblogs.microsoft.com › dev blogs › powershell team › hosting powershell in a python script
Hosting PowerShell in a Python script - PowerShell Team
June 30, 2022 - I’ve been aware of IronPython (Python that tightly integrates .NET) for a long time, and we met with Jim Hugunin shortly after he arrived at Microsoft and PowerShell was just getting underway, but the group is using cPython so I went hunting for Python modules that host .NET and found the pythonnet module.