# How to install and import jgrapht in Python mode

**URL:** <https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620>\
**Category:** Processing.py\
**Created:** [November 22, 2020, 9:10pm UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620 "2020-11-22T21:10:13Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 22, 2020, 9:10pm UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/1 "2020-11-22T21:10:13Z")

</div>

Hi all,

I have an issue installing and using the latest version of [jgrapht](https://jgrapht.org/) with Python mode. I used to work with an [older version](https://github.com/ThomasLengeling/jgrapht) 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](https://sourceforge.net/projects/jgrapht/files/JGraphT/Version%201.5.0/jgrapht-1.5.0.zip/download?use_mirror=deac-fra&download=), 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

```auto

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

```auto
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 ?

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [November 22, 2020, 9:12pm UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/2 "2020-11-22T21:12:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 22, 2020, 10:26pm UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/3 "2020-11-22T22:26:15Z")

</div>

> [@solub](#):
>
> Does that mean that _jgrapht_ is only compatible with Processing 4?

[https://SourceForge.net/p/jgrapht/news/2020/02/jgrapht-version-140-released/](https://SourceForge.net/p/jgrapht/news/2020/02/jgrapht-version-140-released/)

> [@Skia Graphics Library as a renderer in Processing](https://discourse.processing.org/t/skia-graphics-library-as-a-renderer-in-processing/25580/4):
>
> Processing 3’s IDE (PDE) is bundled w/ Java 8: [https://github.com/JetBrains/skija/issues/57](https://github.com/JetBrains/skija/issues/57)

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 22, 2020, 11:47pm UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/4 "2020-11-22T23:47:31Z")

</div>

I just installed Processing 4.0 alpha 2 following the instructions from the official [repo](https://github.com/processing/processing4) 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](https://sourceforge.net/projects/jgrapht/files/JGraphT/Version%201.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.

```auto
from org.jgrapht.graph import SimpleWeightedGraph, DefaultWeightedEdge
from org.jgrapht.alg.shortestpath import DijkstraShortestPath

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 23, 2020, 1:11am UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/5 "2020-11-23T01:11:09Z")

</div>

> [@solub](#):
>
> I went on installing JGraphT version [1.3.0](https://sourceforge.net/projects/jgrapht/files/JGraphT/Version%201.3.0/)

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

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [November 23, 2020, 2:13am UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/6 "2020-11-23T02:13:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [November 23, 2020, 4:37am UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/7 "2020-11-23T04:37:08Z")

</div>

I’ve just tested [Processing 4.0 alpha 1](https://github.com/processing/processing4/releases/tag/processing-1270-4.0a1), 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](https://github.com/jdf/processing.py/issues/382) and (self)-assigned to jdf to fix.

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 23, 2020, 11:36am UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/8 "2020-11-23T11:36:35Z")

</div>

@GoToLoop – **1.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.

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [April 22, 2021, 10:30am UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/9 "2021-04-22T10:30:25Z")

</div>

@villares @tabreturn: Do you know if the latest release of Processing 4 ([alpha 3](https://github.com/processing/processing4/releases)) works with Python mode ?

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [April 22, 2021, 10:51am UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/10 "2021-04-22T10:51:03Z")

</div>

Alpha 3 isn’t working with Python Mode ☹

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

\* tested on Linux

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [April 22, 2021, 10:58am UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/11 "2021-04-22T10:58:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [April 22, 2021, 1:44pm UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/12 "2021-04-22T13:44:20Z")

</div>

> [@solub](#):
>
> a bit disappointing.

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

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [June 17, 2021, 11:09am UTC](https://discourse.processing.org/t/how-to-install-and-import-jgrapht-in-python-mode/25620/13 "2021-06-17T11:09:43Z")

</div>

Python Mode for Processing 4 (alpha 4) update –

> [@Python Mode for Processing 4 alpha](https://discourse.processing.org/t/python-mode-for-processing-4-alpha/30760):
>
> For anybody who wants to help test this – Download this file: [https://github.com/tabreturn/processing.py-for-processing-4/raw/main/PythonMode-4.0a4.zip](https://github.com/tabreturn/processing.py-for-processing-4/raw/main/PythonMode-4.0a4.zip) Extract it and place the PythonMode directory in your sketchbook modes directory (see File \> Preferences menu in Processing for this location). Replace any existing PythonMode files. If you’re running Processing 3 and 4 on the same system, they both use the same sketchbook location (but this build seems to work fine in both). To report issue…
