How can I check what version of the Python Interpreter is interpreting my script?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Put something like:
at the top of your script.
Note that depending on what else is in your script, older versions of python than the target may not be able to even load the script, so won't get far enough to report this error. As a workaround, you can run the above in a script that imports the script with the more modern code.
If you want to detect pre-Python 3 and don't want to import anything...
...you can (ab)use list comprehension scoping changes and do it in a single expression:
This information is available in the sys.version string in the sys module:
Human readable:
For further processing:
To ensure a script runs with a minimal version requirement of the Python interpreter add this to your code:
This compares major and minor version information. Add micro (=
0
,1
, etc) and even releaselevel (='alpha'
,'final'
, etc) to the tuple as you like. Note however, that it is almost always better to "duck" check if a certain feature is there, and if not, workaround (or bail out). Sometimes features go away in newer releases, being replaced by others.Use
platform
'spython_version
from the stdlib:The simplest way
Just type python in your terminal and you can see the version as like following
To verify the Python version for commands on Windows, run the following commands in a command prompt and verify the output
Also, To see the folder configuration for each Python version, run the following commands: