using #!/usr/bin/env python3 shebang with Windows

前端 未结 3 1727
野的像风
野的像风 2021-01-18 02:18

I\'m trying to run a Python script from the command line as a command on Windows -- so no usage of \"Python\" or \".py\". If my script is named \"testing.py\", I am attempti

3条回答
  •  甜味超标
    2021-01-18 02:58

    No, Windows does not support shebang lines.

    The documentation you've linked relates to the py launcher installed by Python, which can interpret various shebang lines to choose a Python version to run a script with.

    setuptools is able to generate wrapper .exes for your Python scripts, but it gets a little involved and already assumes you have a package with a setup.py and so on.

    Locally, if you really, really need this, you probably could add .py to the PATHEXT environment variable, so the Windows command line looks up .pys like it looks up .exes (and various others; the current modern default is .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC). However, this will naturally not scale for distributing apps, as all of your users would need to set that too.

    My recommendation is to stick with just that boring old python testing.py, really.

提交回复
热议问题