Python on Windows doesn't accept cmd line args

I have installed Python (3.14.3) on Windows using the new Windows Installer (25.2)
I previously had Python(s) 3.12, 3.13 and 3.14.2 installed using the “old” installer. All of those were uninstalled, machine rebooted.

From the command line, py launches the interpreter, as does python and python3 and python3.14. All good.

Running my script in different ways gives problematic behaviour:

# myscript.py
import os
import sys

print(sys.executable)
print(sys.version)

os.system('py --version')
os.system('python --version')
os.system('python3 --version')

print(f'There are {len(sys.argv)} cmd line args')
print(sys.argv)

Working way 1:

If I run my script with py it works fine, and receives the cmd line args.

C:\wrk> py myscript.py one two three
C:\Users\Peter\AppData\Local\Python\pythoncore-3.14-64\python.exe
3.14.3 (tags/v3.14.3:323c59a, Feb  3 2026, 16:04:56) [MSC v.1944 64 bit (AMD64)]
Python 3.14.3
Python 3.14.3
Python 3.14.3
There are 4 cmd line args
['myscript.py', 'one', 'two', 'three']
C:\wrk>

Failing way 2:

If I run my script with the association the script runs, but doesn’t receive my command line args, and the launches for python and python3 emit “Access is denied” messages.

C:\wrk> myscript.py one two three
C:\Users\Peter\AppData\Local\Python\pythoncore-3.14-64\python.exe
3.14.3 (tags/v3.14.3:323c59a, Feb  3 2026, 16:04:56) [MSC v.1944 64 bit (AMD64)]
Python 3.14.3
Access is denied.
Access is denied.
There are 1 cmd line args
['C:\\wrk\\myscript.py']
C:\wrk>

Failing way 3:

I can also launch the program using the PATHEXT, but this also gives the erroneous behaviour.

C:\wrk> echo %PATHEXT% 
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY
C:\wrk> myscript one two three
C:\Users\Peter\AppData\Local\Python\pythoncore-3.14-64\python.exe
3.14.3 (tags/v3.14.3:323c59a, Feb  3 2026, 16:04:56) [MSC v.1944 64 bit (AMD64)]
Python 3.14.3
Access is denied.
Access is denied.
There are 1 cmd line args
['C:\\wrk\\myscript.py']
C:\wrk>

The previous install of python had the way 1, way 2 and way 3 all working with the same result as way 1. So it seems to be something to do with how the new Windows Installer is setting it up. Is this a bug in the new Windows installer? Is there some setting not being set/being set incorrectly? How can I work around this? (I have some idea it has to do with associations and “%*”, but I’m not sure where to set that.)

Any ideas or solution most welcome.

1 Like

I’d recommend adding print(sys.executable) and print(sys.version) to your tests. Just to verify which Python executable was invoked.

2 Likes

This might be caused by an old issue, though I’m uncertain. It’s explained here and the fix is to make a Windows Registry change: https://stackoverflow.com/questions/15281951/sys-argv-contents-when-calling-python-script-implicitly-on-windows

It looks like it was discussed in this bug report, though no resolution was made: Fix .py(w) file association with Python 3 Windows installer · Issue #84434 · python/cpython · GitHub

2 Likes

Good idea. Added sys.executable and version to test. Results are the same in every case.

1 Like

I changed

Computer\HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command

to

“C:\Users\Peter\AppData\Local\Python\pythoncore-3.14-64\python.exe” “%1” %*

and rebooted, but still the same problem - it’s not accepting command line arguments (except for sys.argv[0], which is being populated correctly.)

I then found the key:

Computer\HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

which had the same value (missing the %*), so I updated that as well.

This has fixed the missing cmd line args issue. Putting it here for any others with the same problem to find. I’ve also added a note on the stackoverflow post.

The issue with “Access is denied” is still there. It might be a different issue, so I’ll post that as a separate help request.

1 Like