Detect python version in shell script

前端 未结 14 2126
清歌不尽
清歌不尽 2020-12-07 20:26

I\'d like to detect if python is installed on a Linux system and if it is, which python version is installed.

How can I do it? Is there something more graceful than

14条回答
  •  醉话见心
    2020-12-07 20:54

    You can use this command in bash:

    PYV=`python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";`
    echo $PYV
    

提交回复
热议问题