How do I get to a Jython command line?

I want to experiment with using IntelliJ IDEA as an IDE for writing scripts in Jython that reside in the “user-lib/pylib” directory. But in order to configure IntelliJ to recognise Jython projects, I need to tell it where the Jython SDK is located. And so far I can’t find it! So:

  1. How do I get to a Jython command line and/or SDK (are they the same thing?) ?

  2. Does anyone have any tips on integrating Jython into IntelliJ?

FWIW I’m currently doing this under Linux

You really can’t. The closest thing you can do is install Jython manually, then symlink the site-packages of that installation with the pylib directory (see here for details) - which means you’ll also have to develop on the gateway machine (or at least, a machine with a gateway installed).

Jetbrains IDEs don’t seem to have great support for Jython, last I checked. That may have changed, but it’ll probably be a bit of a hurdle. You’ll probably also want to use something like https://github.com/thecesrom/Ignition to “stub” Ignition scripting functions - there’s no way to access Ignition’s built in scripting functions outside of an actual Ignition runtime.

If you’re looking for an IDE to get familiar with Jython and what’s available, I’ve used PyCharm a fair amount with Jython.

As Paul said, though, if you’re looking to run your Ignition Python scripts, you won’t be able to do that from outside Ignition if they’re using anything Ignition-specific (which almost all of them normally do). Any system. functions need to be executed in Ignition directly, not in an external IDE, to function.

That said, if you do want to just write Python and play around with executing it in Jython, you can do so with the following steps:

You’ll want to install a separate copy of Jython on your system. Head over to jython.org and download the Jython Installer from the downloads page. Make sure your Java version is 11 to match Ignition 8’s.

After that, you can add Jython’s interpreter to PyCharm (Or possibly IDEA’s Python plugin, though I’ve never tried that myself), and you’re off to the races.

If the main reason you’re asking about an external IDE is for some of the nice features that most IDEs have, rest assured we have quite a few tickets in our system to improve our script editor / Python dev environment. It currently does fine, but there are quite a few things we could do to improve things in the future. Although it’s a ways off, we will certainly be making some improvements down the road.

1 Like

Oh, and the answer to this: Open the Ignition Designer, go to Tools -> Script Console, and on the right side you'll see the interactive interpreter. Enjoy!

1 Like

Yep, the main reason I'm exploring this is to have a better scripting editor, and not to run Ignition scripts outside of Ignition. In terms of general programming I'm used to working with things like Visual Studio for c#, so I find the functionality of Ignition's built in scripting editors somewhat sparse. And I say that as someone who has also spent a large amount of time developing CimBasic code in the CIMPLICITY HMI, using their built in IDE.

I mentioned IntelliJ as I have been using that as an IDE for learning Java. I have seen references for also using it for Jython (and also CPython) development, but that is predicated on a separate Jython installation being present. In hindsight I'm guessing that Jython is embedded in Ignition and not installed as a separate installation, which makes my question kind of moot.

I'm also vaguely aware that there are requests for better scripting editor support. But I want it now!!!!! Hence my exploring other alternatives :smiley: (and in the process learning the a lot about what I can and can't do with Ignition)

1 Like

I think that doing a manual installation of Jython, and using the stub functions make be the closest I’m going to get to what I want. I’m also currently only learning Ignition and running in a Debian VM (on a Windows machine, that I access via remote desktop from my Mac!) so I’m not concerned about doing my editing on the gateway machine.

From what I saw online yesterday, it should be trivial to use IntelliJ IDEA Community edition to support Jython/Python development. It just requires pointing the IDE at the Python installation. And that location was what I was trying to discern yesterday.

FYI The IntelliJ Python plugin states that it provides the PyCharm functionality in the IntelliJ IDE.

I am using PyCharm with the JythonHelper plugin, and Jython 2.7 as the Project Interpreter, and it all plays nicely.

Also I have added some java and javax “stubs” to the Ignition repo where Java can’t/shouldn’t/mustn’t be installed and Python 2.7 is configured as the Project Interpreter.

1 Like

Does that combination allow for importing from Java? I’ve got Jython code running in IntelliJ using the Jython 2.7 runtime, but IntelliJ warns me about unresolved references - which it then chooses to ignore when running the code! My only current option is to suppress the error.

Screen Shot 2020-07-29 at 11.25.38 AM

With PyCharm + Jython 2.7 + JythonHelper, I just right-click anywhere on the file and select Jython Helper from the context menu and all squiggly red lines go away.

1 Like

And, as expected, JythonHelper (Plugin homepage) is compatible with IntelliJ IDEA, PyCharm, and other JetBrain’s IDEs.

Just consider that JythonHelper only creates stubs for the packages you are importing. If squiggly red lines [re]appear, recreate stubs by selecting Jython Helper from the context menu.

IntelliJ IDEA:

Thanks for that, I was going to try it myself, but you beat me to it.

we have some steps to get the command line,
After the installation is complete, invoke jython.exe from the bin directory inside the destination directory. Assuming that Jython is installed in C:\jython27, execute the following from the [command line](Jython - Installation - Tutorialspoint. A Python prompt (>>>) will appear, in front of which any Python statement or Python script can be executed.