Solution 1
I finally did like this:
That's it!
Solution 2
Here is a solution from various comments from @ErykSun:
Open the system environment variables editor and ensure that "D:\myscripts" is in PATH
(do not use quotes) and ".PY" is in PATHEXT
(do not use quotes).
Create a test file D:\myscripts\test_command.py
with the line import sys; print(sys.executable); print(sys.argv)
.
In a new command prompt that was opened from Explorer (to get the updated environment variables), run the test script from another directory as test_command spam eggs
. If it runs with the expected Python installation and the command-line arguments "spam" and "eggs" are correctly passed, then you're done.
When double-clicking and running at the command prompt, the shell executes the default action for the filetype. If the filetype doesn't explicitly define a default action, the shell uses the "open" action, and if that's not defined it uses the filetype's first defined action, whatever that is. Python configures an "open" action for its "Python.File" filetype and additional context-menu (right-click) actions for editing with IDLE.
There are other directions you can go with this. You can use shell links. Add ".LNK" to PATHEXT
and remove ".PY". Then for each script that you want to run, create a shell link (.LNK shortcut file) in D:\myscripts
that runs the script explicitly as "path\to\python.exe" "\path\to\script". Leave the working directory field empty, so that it inherits the working directory of the parent process. For example, create D:\myscripts\test_command.lnk
to run D:\myscripts\test_command.py
.
In this case, you would run the script as test_command, which will find and execute "test_command.lnk". To get the default Sublime edit action, you would explicitly run test_command.py with the ".PY" extension.
Solution 3
Create an .exe file in c:\python37\scripts\
with this method: How to create a .exe similar to pip.exe, jupyter.exe, etc. from C:\Python37\Scripts?
but it's more complicated since it requires a package, etc.