A lot of thanks for the most of other answers for helping me to find the solution!
My case was to open .py
-files with py.exe
(not python.exe
directly), this case it noted in a couple of comments, but I decided to post this as a separate answer to emphasize the difference.
So I have my .py
-files associated with C:\Windows\py.exe
and in C:\Windows\py.ini
config I have a couple of shebang definitions
[commands]
<my_venv_py> = C:\Programs\my_venv_py\Scripts\python.exe
<my_venv_py_w> = C:\Programs\my_venv_py\Scripts\pythonw.exe
to use in my scripts like this #!<MY_VENV_PY>
.
And on Microsoft Windows 7 [Version 6.1.7601] my python script did NOT received the args like this
script.py 1 2
but this worked fine
py script.py 1 2
File associations were OK
> assoc .py
.py=Python.File
> ftype | grep Python
File STDIN:
Python.CompiledFile="C:\Windows\py.exe" "%1" %*
Python.File=C:\Windows\py.exe "%L" %*
Python.NoConFile="C:\Windows\pyw.exe" "%1" %*
I've tried much of registry changes, but the last helped was the following change (saved to a .reg
-file and run). I've found this registry key searching "%1"
string with initial value "C:\Windows\py.exe" "%1"
and added %*
in the end as other answers note:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Applications\py.exe\shell\open\command]
@="\"C:\\Windows\\py.exe\" \"%1\" %*"
For information, before I tried to setup these keys and values and did not helped (at least before the noted above):
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.py]
@="Python.File"
[HKEY_CURRENT_USER\Software\Classes\.py]
@="Python.File"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.py]
@="Python.File"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py]
@="Python.File"
[HKEY_CLASSES_ROOT\py_auto_file]
@="Python File"
[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Windows\\py.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.File]
@="Python File"
[HKEY_CLASSES_ROOT\Python.File\Shell\Open\command]
@="\"C:\\Windows\\py.exe\" \"%1\" %*"