Making Python scripts run on Windows without specifying “.py” extension

前端 未结 4 1587
甜味超标
甜味超标 2020-12-01 05:52

I want to able to open a command prompt at the folder which contains a python script and just type in the script name without the .py and watch it run.

Following the

相关标签:
4条回答
  • 2020-12-01 06:04

    Add .PY to PATHEXT as noted before

    Then do:

    assoc .py=Python.File
    ftype Python.File=c:\Python27\python.exe "%1" %*
    

    Adding python to the path isn't necessary to execute the script in a command prompt or double clicking in Explorer, only if you want to start an interactive python session or running the script with python yourscript.py

    See http://docs.python.org/2/using/windows.html for more details.

    0 讨论(0)
  • 2020-12-01 06:07

    Create a file named 'personalisedCommand.cmd' in a path folder with this inside:

    @echo off python absolute/path/to/pythonScript

    0 讨论(0)
  • 2020-12-01 06:11

    Modify the PATHEXT variable to include Python scripts. For example, here's mine:

    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY
    

    You can do this every time you open a command console, or just modify your user global environment variables so that every instance of cmd.exe will include it.

    0 讨论(0)
  • 2020-12-01 06:26

    I was able to get it done using this application http://defaultprogramseditor.com/

    0 讨论(0)
提交回复
热议问题