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 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.
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.
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.
In [50]: import platform In [52]: platform.python_implementation() Out[52]: 'CPython'
How about platform
it gives you
platform.python_implementation()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With