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 … Answer from eryksun on discuss.python.org
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows › dev-environment › python
Python on Windows for beginners | Microsoft Learn
April 15, 2026 - To set this variable from the Command Prompt, use: set PYTHONPATH=list;of;paths. To set this variable from PowerShell, use: $env:PYTHONPATH='list;of;paths' just before you launch Python.
🌐
Python.org
discuss.python.org › python help
Powershell and python executables - Python Help - Discussions on Python.org
June 5, 2023 - 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?
🌐
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?

🌐
Jamie Phillips
phillipsj.net › posts › executing-powershell-from-python
Executing PowerShell from Python • Jamie Phillips
October 26, 2020 - def run(self, cmd): completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True) return completed · Let’s make our Python file executable and then create the commands we want to execute. One command has the correct syntax, and one command has bad syntax.
🌐
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?

Find elsewhere
🌐
Python.org
discuss.python.org › python help
Install python with a script or powershell - Python Help - Discussions on Python.org
January 24, 2024 - Im looking for some help with an install script. We want to push out python to end users in the background via powershell or script. Has anyone had any success with it?
🌐
Spiceworks
community.spiceworks.com › programming & development
Powershell vs Python, which to use for scripting (Windows)? - Programming & Development - Spiceworks Community
February 25, 2025 - I know it depends a lot on the ... 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 sc......
🌐
Advanced Installer
advancedinstaller.com › execute-python-script-through-powershell.html
Executing Python Scripts through PowerShell: A Step-by-Step Guide
February 22, 2024 - This article will show you how to execute a Python script from PowerShell and benefit from integrating Python's capabilities in a Windows environment.
🌐
DATA GOBLINS
data-goblins.com › power-bi › powershell-in-python-gui
Running PowerShell from a Python GUI — DATA GOBLINS
November 7, 2022 - I can now run pbi-tools from within python, and use the output for other, downstream programmatic actions. It’s possible to run PowerShell from within python using subprocess.run() and specifying the powershell.exe path.
🌐
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.
🌐
Openai
developers.openai.com › codex › app › windows
Windows – Codex app | OpenAI Developers
May 18, 2026 - You can keep the agent in WSL and still use PowerShell in the terminal, or use WSL for both, depending on your workflow. Codex works best when a few common developer tools are already installed: Git: Powers the review panel in the Codex app and lets you inspect or revert changes. Node.js: A common tool that the agent uses to perform tasks more efficiently. Python: A common tool that the agent uses to perform tasks more efficiently.
🌐
Toptal
toptal.com › developers › gitignore
gitignore.io - Create Useful .gitignore Files For Your Project
Create useful .gitignore files for your project by selecting from 571 Operating System, IDE, and Programming Language .gitignore templates
🌐
Open WebUI
docs.openwebui.com › home
Home / Open WebUI
curl -LsSf https://astral.sh/uv/install.sh | sh DATA_DIR=~/.open-webui uvx --python 3.11 open-webui@latest serve
🌐
PyPI
pypi.org › project › setuptools
setuptools · PyPI
Python :: 3 · Python :: 3 :: Only · Topic · Software Development :: Libraries :: Python Modules · System :: Archiving :: Packaging · System :: Systems Administration · Utilities · Report project as malware · See the Quickstart and the User’s Guide for instructions on how to use Setuptools.
      » pip install setuptools
    
Published   Jul 04, 2026
Version   83.0.0
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1195583 › installing-python-with-powershell-and-system-accou
Installing Python with Powershell and "System" Account - Microsoft Q&A
April 2, 2023 - Hi, I am doing my head in here. I have an installation script that works perfectly for everything through Windows Task Scheduler except Python. It uses the system account on the server to run this task. It doesn't error when installing Python, but what…
🌐
Reddit
reddit.com › r/powershell › turning powershell into a python engine
r/PowerShell on Reddit: Turning PowerShell into a Python Engine
January 10, 2024 -

Last semester, I started work on the Import-Package module. It is still in the prerelease stages as it needs some polishing before going to v1, but I started putting it to use.

Preface: my Import-Package module

PowerShell's Import-Module command (as well as Add-Type) can be used to import C# dlls. However, both commands lack good dependency management.

If a .dll is dependent on another, those dependencies must be prepared and loaded manually. C# .nupkgs are made for automatic dependency management, but Import-Module can only load PowerShell .nupkgs.

There is the PowerShell PackageManagement module that provides functions for installing, updating and removing them, but it doesn't provide methods for loading them.

So, I wrote a module of my own.

Microsoft makes nuget.exe's and dotnet.exe's internals available as C# libraries. Examples are:

  • NuGet.Packaging - used for parsing .nupkgs and .nuspecs

  • Microsoft.NETCore.Platforms - used for identifying OS's as used by nuget.exe and dotnet.exe

All of these libraries are used in Import-Package to parse and load entire .nupkgs from NuGet.

Python.NET

The main reason I set out to write the Import-Package module last semester was to explore ways to automate Edge using webdriver.

NuGet.org offers good Selenium libraries, but doesn't offer great ones for webdriver installation. Python's webdriver-manager library is more robust and better maintained than similar libraries in C#. On top of that, I was also curious to know if cpython's binding API was available in C#.

It is: nuget.org - pythonnet (Python.NET, formerly Python.Runtime)

  • IronPython is also an option. When picking an embedded engine use these considerations:

    • IronPython can be run multithreaded. CPython (Python.NET) can not.

    • CPython (Python.NET) supports the ctypes module. IronPython does not.

    • CPython is the official python engine from Python.org and has a better release schedule than IronPython

      • Currently CPython supports python 3.12, while IronPython is still on python 3.7

Use Cases

The biggest use case for doing this (over just using python.exe) is to make libraries written for Python available for PowerShell.

Here is an example of how I currently use the library:

Python Selenium:

Prepare Python.NET:

using namespace Python.Runtime

Import-Module Import-Package
Import-Package pythonnet

# cpython has a GIL, so in order to use the python API, you need to lock it:
# - Unlocking the GIL does not destroy any python variables or data. It just prevents you from using it.

New-Module -Name "CPython-GIL" -ScriptBlock {
    $state = @{ "lock" = $null }

    function global:Lock-Python {
        Write-Host "Python GIL is now locked. Unlock it ANYTIME with Unlock-Python." -ForegroundColor Yellow
        $state.lock = [Python.Runtime.Py]::GIL()
    }
    function global:Unlock-Python {
        $state.lock.Dispose()
    }

    Export-ModuleMember
} | Import-Module```

Lock-Python # GIL is now locked. Python API is now usable.

$python = @{} # hashtable for my python variables

Load the Python libraries

# Get the webdriver-manager and selenium package objects
$python.webdriver = [Py]::Import( "webdriver_manager" )
$python.selenium = [Py]::Import( "selenium" )

# Import the subpackages. These will be available as a property on the parent package
& {
  [Py]::Import( "webdriver_manager.microsoft" )
  
  [Py]::Import("selenium.webdriver.edge.options")
  [Py]::Import("selenium.webdriver.common.keys") 
  [Py]::Import("selenium.webdriver.edge.service")
}

Prepare Edge and Edge WebDriver

Update/Install msedgedriver.exe and create the Selenium 4 service

$msedge = @{}

# Update and get path to msedgedriver.exe
$msedge.webdriver = $python.webdriver.EdgeChromiumDriverManager().install()

Python.NET objects are designed to be strictly dynamic in nature

  • They don't automatically cast themselves to C#/PowerShell-friendly types.

  • They do support a lot of standard type operands like concatenation and property accessors...

    • ...but I find it best to just cast to a C# type when possible.

Prepare the EdgeOptions object

# Create the EdgeOptions object
$msedge.options = $python.selenium.webdriver.EdgeOptions()

!!!CAREFUL!!!

Chrome-based browsers do not allow you to use a User Data directory via webdriver at the same time as the user.

You can either close all user browsers or clone the default user data instead.

You can obtain the User Data directory directory path from edge://version or chrome://version > Profile Path. The User Data directory is the parent folder to the profile folder

# Paste your Profile Path here:
# - This is the default path for Edge:
$msedge.profile_path = "C:\Users\Administrator\AppData\Local\Microsoft\Edge\User Data\Default"

$msedge.profile_folder = $msedge.profile_path | Split-Path -Leaf
$msedge.user_data = $msedge.profile_path | Split-Path -Parent

$msedge.options.add_argument("--user-data-dir=$( $msedge.user_data )")
$msedge.options.add_argument("--profile-directory=$( $msedge.profile_folder )")
$msedge.options.add_argument("--log-level=3") # Chrome.exe and Edge.exe can be extremely noisy
$msedge.options.page_load_strategy="none" # Allows controlling the browser before page load

Automate away!

# Start the automated browser
$Window = & {
  # Internally, python keyword arguments are actually a kw object:
  $service = [Py]::kw( "service", $msedge.service )
  $options = [Py]::kw( "options", $msedge.options )
  
  $python.selenium.webdriver.Edge( $service, $options )
}

# go to url:
$Window.get( "edge://version" )
# run javascript:
$Window.execute_script( "window.open('https://google.com','_blank')" )

FUTURE PLANS:

I've unfortunately remembered that V8 is also embeddable. There's also already a C# bindings library for it: https://github.com/Microsoft/ClearScript

If I can get it working, I'll share my results.

EDIT: done - Turning PowerShell into a JavaScript Engine

🌐
Zephyr Project
docs.zephyrproject.org › latest › develop › getting_started › index.html
Getting Started Guide — Zephyr Project Documentation
2 weeks ago - Python’s virtual environment activation in PowerShell requires running a script itself, which needs to be allowed.