Why do people write #!/usr/bin/env python on the first line of a Python script?

后端 未结 21 1717
刺人心
刺人心 2020-11-21 06:16

It seems to me like the files run the same without that line.

21条回答
  •  梦如初夏
    2020-11-21 07:11

    You can try this issue using virtualenv

    Here is test.py

    #! /usr/bin/env python
    import sys
    print(sys.version)
    

    Create virtual environments

    virtualenv test2.6 -p /usr/bin/python2.6
    virtualenv test2.7 -p /usr/bin/python2.7
    

    activate each environment then check the differences

    echo $PATH
    ./test.py
    

提交回复
热议问题