what shebang to use for python scripts run under a pyenv virtualenv

前端 未结 5 1737
攒了一身酷
攒了一身酷 2020-12-08 18:34

When a python script is supposed to be run from a pyenv virtualenv what is the correct shebang for the file?

As an example test case, the d

5条回答
  •  离开以前
    2020-12-08 18:39

    If you need to use more shell than you can put in the #! shebang line, you can start the file with a simple shell script which launches Python on the same file.

    #!/bin/bash
    "exec" "pyenv" "exec" "python" "$0" "$@"
    # the rest of your Python script can be written below
    

    Because of the quoting, Python doesn't execute the first line, and instead joins the strings together for the module docstring... which effectively ignores it.

    You can see more here.

提交回复
热议问题