How do I check what version of Python is running my script?

前端 未结 22 2089
醉话见心
醉话见心 2020-11-22 04:11

How can I check what version of the Python Interpreter is interpreting my script?

22条回答
  •  青春惊慌失措
    2020-11-22 04:38

    Here's a short commandline version which exits straight away (handy for scripts and automated execution):

    python -c "print(__import__('sys').version)"
    

    Or just the major, minor and micro:

    python -c "print(__import__('sys').version_info[:1])" # (2,)
    python -c "print(__import__('sys').version_info[:2])" # (2, 7)
    python -c "print(__import__('sys').version_info[:3])" # (2, 7, 6)
    

提交回复
热议问题