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

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

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

22条回答
  •  再見小時候
    2020-11-22 04:52

    To check from the command-line, in one single command, but include major, minor, micro version, releaselevel and serial, then invoke the same Python interpreter (i.e. same path) as you're using for your script:

    > path/to/your/python -c "import sys; print('{}.{}.{}-{}-{}'.format(*sys.version_info))"
    
    3.7.6-final-0
    

    Note: .format() instead of f-strings or '.'.join() allows you to use arbitrary formatting and separator chars, e.g. to make this a greppable one-word string. I put this inside a bash utility script that reports all important versions: python, numpy, pandas, sklearn, MacOS, xcode, clang, brew, conda, anaconda, gcc/g++ etc. Useful for logging, replicability, troubleshootingm bug-reporting etc.

提交回复
热议问题