Is there a way to detect that the interpreter that executes the code is Jython or CPython?
I have another post: Jython does not catch Exceptions. For this case, if I know the interpreter is Jython, I can have different code that should work.
if JYTHON:
sys.path.insert(0, os.path.dirname(__file__))
from utils import *
else:
from .utils import *
Reference implementation of Python, called CPython, is written in C language. Jython on the other hand is completely written in Java and is a JVM implementation. Standard Python is available on multiple platforms. Jython is available for any platform with a JVM installed on it.
Python is an interpreted language, which means the source code of a Python program is converted into bytecode that is then executed by the Python virtual machine. Python is different from major compiled languages, such as C and C + +, as Python code is not required to be built and linked like code for these languages.
CPython is the default byte-code interpreter of Python, which is written in C.
Check Python Version: Script To check which Python version is running, you can use either the sys or the platform module. The script will be the same for Windows, macOS, and Linux. Of course, you can easily obtain the individual components of this tuple using an index (e.g. sys. version_info[0] ) or a name (e.g. sys.
There is an official way to do it! :-) Please have a look at
http://docs.python.org/2/library/platform.html#platform.python_implementation
Returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.
New in version 2.6.
I did not know that before.
Old answer:
There probably is no standardized interface, but you can use some educated guessing, based on e.g. sys.executable
(http://docs.python.org/2/library/sys.html#sys.executable), and sys.version
. Furthermore, some interpreters for sure provide features that are specific to them, which you can make use of.
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