Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

cpython

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..." 
like image 843
Stuart Berg Avatar asked Feb 05 '13 22:02

Stuart Berg


People also ask

How do I know if I am using CPython?

Python is probably already installed on your system. To check if it's installed, go to Applications>Utilities and click on Terminal. (You can also press command-spacebar, type terminal, and then press Enter.) If you have Python 3.4 or later, it's fine to start out by using the installed version.

How do I know what version of CPython I have?

If you have Python 3.7 installed, run pip -V and check what python version is printed. On your machine, pip may be an alias to pip3.

What is CPython interpreter?

CPython can be defined as both an interpreter and a compiler as it compiles Python code into bytecode before interpreting it. It has a foreign function interface with several languages, including C, in which one must explicitly write bindings in a language other than Python.


2 Answers

In [50]: import platform     In [52]: platform.python_implementation() Out[52]: 'CPython' 
like image 67
unutbu Avatar answered Sep 29 '22 13:09

unutbu


How about platform

it gives you

platform.python_implementation() 
like image 42
Jakob Bowyer Avatar answered Sep 29 '22 13:09

Jakob Bowyer