odoust
odoust

Reputation: 11

Learning how to use Jython - ResourceWarning error

I'm trying to learn how to use Jython for a Java Swing project,

I've managed to import the dependency on IntelliJ and I want to test Jython by running some very simple code:

import org.python.util.PythonInterpreter;

public class test {

    public static void main(String[] args) {
        System.out.println("Java Hello");
        PythonInterpreter pi = new PythonInterpreter();
        pi.exec("print('Python Hello')");
    }

}

The console output is:

Java Hello
Exception in thread "test" Traceback (most recent call last):
  File "/Users/a/Desktop/python/Lib/site.py", line 68, in <module>
    import os
  File "/Users/a/Desktop/python/Lib/os.py", line 50, in <module>
    import posixpath as path
  File "/Users/a/Desktop/python/Lib/posixpath.py", line 17, in <module>
    import warnings
  File "warnings.py", line 395, in <module>
  File "warnings.py", line 395, in <module>
  File "__pyclasspath__/_warnings.py", line 106, in <module>
NameError: name 'ResourceWarning' is not defined

I have not managed to find anything to guide me online,

Any help would be greatly appreciated!

Upvotes: 1

Views: 882

Answers (1)

Mark T.
Mark T.

Reputation: 11

It's an error throws by Python that it can't find Jython library. As a workaround, add the Jython lib folder to the python classpath. Then assign python interpreter to your project with updated classpath.

On the pom file, change the scope to: provided.

enter image description here

Cheers, Mark

Upvotes: 1

Related Questions