How to install and import jgrapht in Python mode

Hi all,

I have an issue installing and using the latest version of jgrapht with Python mode. I used to work with an older version tailored for Processing but that port is very limited and is missing most of the functions and classes of the original library.

I have downloaded version 1.5.0, put it in the library folder and renamed it jgrapht.

However:

  • the library doesn’t show up in the sketch/import a library menu
  • manual import with add_library('jgrapht') returns an error:

“Maybe there’s an unclosed paren or quote mark somewhere before this line?”

  • generating an exception makes possible to overcome this error but then no class seems accessible

try:
    add_library('jgrapht')
except:
    pass

G = SimpleWeightedGraph(DefaultWeightedEdge)

NameError: name 'SimpleWeightedGraph' is not defined

  • When dropping the jgrapht-core-1.5.0 jar file directly onto the folder and importing manually a class, an UnsupportedClassVersionError is returned
from org.jgrapht.alg.shortestpath import DijkstraShortestPath

java.lang.UnsupportedClassVersionError: org/jgrapht/alg/shortestpath/DijkstraShortestPath has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Does that mean that jgrapht is only compatible with Processing 4 ?
If so, does Python mode work with Processing 4 ?

I’ve never used jgrapht, but I did compile Processing 4 a while back – it seemed to work fine with Python mode.

2 Likes

https://SourceForge.net/p/jgrapht/news/2020/02/jgrapht-version-140-released/

1 Like

I just installed Processing 4.0 alpha 2 following the instructions from the official repo but it seems Python mode doesn’t work correctly. Pressing the “play” button doesn’t launch anything: no canvas window, no working console.

Can anyone confirm this ? Just to be sure I’m not the only one getting this issue.

Edit: Following the clarification from @GoToLoop I went on installing JGraphT version 1.3.0 and all seems to work fine now with Processing 3 Python mode. Just be sure to drop the jgrapht-core-1.3.0.jar file (inside the jgrapht/lib folder) on your sketch window and manually import the classes of your choice.

from org.jgrapht.graph import SimpleWeightedGraph, DefaultWeightedEdge
from org.jgrapht.alg.shortestpath import DijkstraShortestPath
1 Like

My link was about version [1.4.0]. Was there some other reason you’ve picked [1.3.0] instead? :thinking:

3 Likes

There was an open issue on Python mode on Processing 4, but I think eventually it will work (I hope so!)

1 Like

I’ve just tested Processing 4.0 alpha 1, which works fine with Python Mode. This issue must have crept in at alpha 2. As @villares has noted, the source of the problem has been identified and (self)-assigned to jdf to fix.

2 Likes

@GoToLoop1.4.0 is indeed to way to go ! I totally misread the description and thought the jump to Java 11 was from v1.4.0 included

@tabreturn, @tabreturn – Thank you so much for all the clarifications ! Can’t wait to have Python mode running on Processing 4.

All the best to everyone.

1 Like

@villares @tabreturn: Do you know if the latest release of Processing 4 (alpha 3) works with Python mode ?

1 Like

Alpha 3 isn’t working with Python Mode :frowning_face:

I get an error message that reads: WARNING: An illegal reflective access operation has occurred

* tested on Linux

2 Likes

Thank you so much for the quick testing ! I also had an error last time I checked, a bit disappointing.

1 Like

I’d like to mention this is the number one understatement of the year, at this point…

1 Like

Python Mode for Processing 4 (alpha 4) update –

2 Likes