How can I tell which python implementation I'm using?

PythonCpython

Python Problem Overview


Python has a few different implementations: CPython, Jython, PyPy, etc. I want to programmatically determine which implementation my code is running on. How can I do that?

To be specific, write a function called get_implementation_name() for me:

impl_name = get_implementation_name()
if impl_name == "CPython":
  print "I can abuse CPython implementation details. (I'm a bad, bad man.)"
elif impl_name == "PyPy":
  print "Can't count on reference-counting garbage collection here..."
else:
  print "I better be careful..."

Python Solutions


Solution 1 - Python

In [50]: import platform    
In [52]: platform.python_implementation()
Out[52]: 'CPython'

Solution 2 - Python

How about platform

it gives you

platform.python_implementation()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStuart BergView Question on Stackoverflow
Solution 1 - PythonunutbuView Answer on Stackoverflow
Solution 2 - PythonJakob BowyerView Answer on Stackoverflow