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

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

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

22条回答
  •  眼角桃花
    2020-11-22 04:30

    Several answers already suggest how to query the current python version. To check programmatically the version requirements, I'd make use of one of the following two methods:

    # Method 1: (see krawyoti's answer)
    import sys
    assert(sys.version_info >= (2,6))
    
    # Method 2: 
    import platform
    from distutils.version import StrictVersion 
    assert(StrictVersion(platform.python_version()) >= "2.6")
    

提交回复
热议问题