Conditional shebang line for different versions of Python

后端 未结 2 472
天涯浪人
天涯浪人 2021-01-17 11:44

I have a problem when trying to run a python script on two different computers. On each computer I would like to run the script using python version 2.7.3 however the probl

2条回答
  •  不要未来只要你来
    2021-01-17 11:56

    #!/bin/sh
    # -*- mode: Python -*-
    
    """:"
    # bash code here; finds a suitable python interpreter and execs this file.
    # prefer unqualified "python" if suitable:
    python -c 'import sys; sys.exit(not (0x020500b0 < sys.hexversion < 0x03000000))' 2>/dev/null \
        && exec python "$0" "$@"
    for pyver in 2.6 2.7 2.5; do
        which python$pyver > /dev/null 2>&1 && exec python$pyver "$0" "$@"
    done
    echo "No appropriate python interpreter found." >&2
    exit 1
    ":"""
    
    import sys
    print sys.version
    

    taken from https://github.com/apache/cassandra/blob/trunk/bin/cqlsh

提交回复
热议问题