anaconda - In Python how do I test if the interpreter is running Pyston, Jython, CPython? -


i test inside running python program if interpreter running pyston, jython, ironpython, pypy , on.

the things come mind pattern matching on system.version , checking magic number imp.get_magic() both of these seem little frail , hacky. other suggestions?

edit: user2357112 comes through again.

i tried running following code on every python version had installed, , differentiates jython, pyston, , various cpythons. falls down in python before 2.6, , anaconda variant of cpython. anaconda, may right thing though.

here program , results. feel free note other kinds of python or not work on.

import platform print(platform.python_implementation()) 

and shell script:

for v in $(pyenv versions); # not quite right     pyenv local $v     echo "version $v"     python /tmp/foo.py     echo "===================" done 

and got output:

=================== version 2.1.3 traceback (most recent call last):   file "/tmp/foo.py", line 1, in ?     import platform importerror: no module named platform =================== version 2.2.3 traceback (most recent call last):   file "/tmp/foo.py", line 1, in ?     import platform importerror: no module named platform =================== version 2.3.7 traceback (most recent call last):   file "/tmp/foo.py", line 2, in ?     print(platform.python_implementation()) attributeerror: 'module' object has no attribute 'python_implementation' =================== version 2.4.6 traceback (most recent call last):   file "/tmp/foo.py", line 2, in ?     print(platform.python_implementation()) attributeerror: 'module' object has no attribute 'python_implementation' =================== version 2.5.6 traceback (most recent call last):   file "/tmp/foo.py", line 2, in <module>     print(platform.python_implementation()) attributeerror: 'module' object has no attribute 'python_implementation' =================== version 2.6.9 cpython =================== version 2.7.12 cpython =================== version 2.7.13 cpython =================== version 2.7.8 cpython =================== version 3.0.1 cpython =================== version 3.1.5 cpython =================== version 3.2.6 cpython =================== version 3.3.5 cpython =================== version 3.3.6 cpython =================== version 3.4.2 cpython =================== version 3.5.0 cpython =================== version 3.5.1 cpython =================== version 3.5.2 cpython =================== version 3.6.0 cpython =================== version 3.6.0a4 cpython =================== version 3.6.0b2 cpython =================== version 3.6.1 cpython =================== version 3.6.2 cpython =================== version 3.7-dev cpython =================== version anaconda2-4.1.1 cpython =================== version anaconda3-4.1.0 cpython =================== version jython-2.7.1b3 jython =================== version pypy2-5.4.1 pypy =================== version pypy2-5.6.0 pypy =================== version pypy-2.6.1 pypy =================== version pypy3-2.3.1 pypy =================== version pypy3-2.4.0 pypy =================== version pypy3.5-5.8.0 pypy =================== version pypy-5.0.1 pypy =================== version pypy-5.3.1 pypy =================== version pyston-0.6.0 pyston =================== version pyston-0.6.1 pyston =================== 

as user2357112 mentioned, can check platform.python_implementation() == "pyston", can see in source.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -