04 January 2012

IntelliJ PyCharm 2.0 and Jython 2.2 don't really go together

UPDATE: Dmitry Jemerov from IntelliJ responded, explaining what the situation is. TL;DR: 2.2 is simply too old, other features might come if there is demand. I've amended the post to reflect this.

Let me preface this rant by saying that I've been happily using JetBrains PyCharm for a few months, and it's certainly one of the best Python IDEs out there. The price is ridiculously low and if you're serious about Python, buying PyCharm is one of the best investments you can make. It can be used for free for 30 days, so you really should give it a shot.

This said, if you happen to work with Jython 2.2, you'll probably want to use something else. The claim that Jython is fully supported as a runtime, while literally true, is somehow stretched is only valid for 2.5+.

Let's say you work on Windows, and you have your Jython installed under C:\jython-2.2 (yes, it's damn old, but it's still the most widely-deployed release out there -- just ask IBM and Oracle).

You create a new project in PyCharm, then go to Settings -> Python interpreter, remove the preconfigured CPython runtime, then click on Add and point to your C:\jython-2.2\jython.bat. Bang, "SDK is not valid". The list of library paths, which supposed to be automatically generated by the IDE picking up the environment configuration, is now empty.

Still, PyCharm should be smart enough to parse arbitrary .py files in specific directories, right? So let's click on Add... to point to C:\jython-2.2\Lib, then OK.
Now let's create a .py file, "from pprint import pprint", the module is recognised; "Run" the script, output is correct, life is good: Jython is indeed supported as a Python runtime.

Ok, let's do some file I/O, "import os"... uh, os is not recognised as a valid module. Same for sys. Apparently, they are somewhat special in Jython and are implemented directly into the main jar, so PyCharm can't see them for autocompletion or any other smart feature. I don't know what else is "special" in Jython 2.2, but I'd rather not have to find out.

Which brings us to the main shortcoming of PyCharm as a Jython IDE: it simply won't recognise or parse any Java jar. This is somewhat surprising, considering how the program is basically a spin-off of IntelliJ IDEA, a Java IDE, and is completely built on Java. In fact, it shares the codebase with the Python Plugin for IDEA. One would think PyCharm would be ideally suited to the task of handling the "Python on Java" mesh that is Jython, but alas that's not the case. A quick search on the IntelliJ forum brings up recent posts stating that full Jython support for autocompletion is simply not on the cards; Jython is supported as a runtime and nothing more. In fact, the Python plugin for IDEA probably handles a Jython setup better than PyCharm, and that's not going to change any time soon. The main target for PyCharm are clearly Django/web developers, not integrators. UPDATE: see this blog post for more details on the real situation.

This state of things is a bit saddening. I don't know if this is a way for JetBrains to avoid cannibalizing its main cash-cow (IDEA), or simply a commercial oversight; the fact is that we have a product, ideally positioned to completely own a niche, which simply refuses to do so and actually delivers a second-rate experience. I hope JetBrains will re-evaluate their stance at some point, because it's a bit of a shame really.


Giulio Piancastelli said...

I love your wrap-ups, but this is missing the part where you try PyDev for Jython development and fall in love with Eclipse again.

Giacomo Lacava said...

Are you stalking me on G+ ? I actually just posted something about that... I wouldn't say I "fell in love again", but certainly the Eclipse/PyDev combo seems to have the most complete feature matrix when it comes to Jython.

Giulio Piancastelli said...

No stalking - well, not on G+ anyway. It just occurred to me that you could have tried PyDev while reading your latest tweets about the unexpected lack of Jython support in PyCharm.

Giacomo Lacava said...

For the record, I actually tried NetBeans before going back to Eclipse. From my G+ feed:

"Netbeans supports Jython!".
Installed NB, New Project, no sign of Python or Jython. Looked under Plugins, no sign of Python or Jython. Back to Google, found experimental plugin repository, configured, Python plugin appears! Installed, restarted NB, New Project -> Python, set runtime to jython, import sys, sys-dot-ctrl-space -> No suggestion. Window -> Python console, error. Changed Jython version, different error.
Uninstalled NetBeans.

Giulio Piancastelli said...

I appreciated NetBeans for GUI (i.e. Swing) programming - but that's because when I tried the standard tools available in Eclipse I couldn't get my head around some weird behaviour, e.g. adding an initially empty table to a panel shows nothing on the panel instead of some kind of predefined rectangular area representing the table - and I heard folks able to do Ruby programming on it, but as a general rule I try to stay as far away as I can, because I just don't like the way it works. To each his own, I guess.

Dmitry Jemerov said...

I've replied to this on the PyCharm blog:

Giulio Piancastelli said...

re the follow-up on the PyCharm blog, they may have the edge against PyDev on Jython version: if you read the PyDev blog, it seems that for various reasons (some better than others) the Eclipse plugin will stay with 2.2 for quite a while...

Giulio Piancastelli said...

Some interesting update about Jython: http://fwierzbicki.blogspot.com/2012/03/adconion-to-fund-jython-27.html