How does Python Mode actually work?

Out of personal interest, and to get to understand Processing better:
How does Python Mode actually work?
When I started with Python Mode I was already wondering because I can’t recall having had to tell Processing where Python is installed on my computer, which usually is necessary in any other IDE or editor I am using, from SublimeText to PyCharm.
And when I am getting an error, it often is a Java error message(Especially those “weird” errors that don’t directly come from code, like when stuff is crashing). Does Python Mode actually run Python? It looks to me as if Python Mode might mean coding in Python but your code gets translated to Java, and then Processing runs that. I might be wrong. Really interested in this topic, looking forward to some clarity on this.


This may be helpful: Python, Jython and Java.


You should read that link in full, but an extreme summary:

Python mode bundles Python 2.7 (with quirks) which it runs directly on the Java Virtual Machine (JVM) using Jython. This is what allows it to magically connect directly with Processing’s Java library ecosystem. This also what prevents it from using any system Python, from using CPython libraries, or from using Python 3 syntax.


When Processing moves to GraalVM things will get even more interesting :slight_smile:

For related background discussion of Processing, JVM, GraalVM, and other languages: Processing's eventual switch from Java as primary language, over to Python?