Detect python version in shell script

前端 未结 14 2102
清歌不尽
清歌不尽 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:45

    python -c 'import sys; print sys.version_info'
    

    or, human-readable:

    python -c 'import sys; print(".".join(map(str, sys.version_info[:3])))'
    

提交回复
热议问题