4

Im trying to use java to run a python function through jython.jar. I'm using a python module that is downloaded from web which needs python 2.6 or higher. I'm pretty sure that my python is version 2.7.2. However, when I try to run the java program, it continues to report python 2.5 detected. How can I resolve this?

My code is:

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       ...
                //cmd
                String command = "\"xml\\" + name2 + "\"";
                PythonInterpreter python = new PythonInterpreter(null, new PySystemState());
                PySystemState sys = Py.getSystemState();
                sys.path.append(new PyString("C:\\Python27\\Lib\\site-packages"));
                python.execfile("work1.py");
            }
        }
    }
}

And the error is:

Exception in thread "main" Traceback (most recent call last):   File "work1.py", line 8, in <module>
    import networkx as nx   File "C:\Python27\Lib\site-packages\networkx\__init__.py", line 39, in <module>
    raise ImportError(m % sys.version_info[:2]) ImportError: Python version 2.6 or later is required for NetworkX (2.5 detected). Java Result: 1
1
  • Have you tried the obvious, namely, downloading the latest version of Jython and replacing your jython.jar? It sounds like you have an older version of Jython. Commented Jun 27, 2014 at 20:26

1 Answer 1

2

You need to use Jython 2.7b3, 2.7 beta adds language compatibility with CPython 2.7... http://comments.gmane.org/gmane.comp.lang.jython.devel/6145

2.7 beta 4 will come in July and after that a feature freeze. I suggest you join the python-dev mailing list to stay aware of new releases. Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

aissacf is correct. jython is alternative implementation of Python. It does not use the version of Python installed on the machine. aka. CPython. i.e. jython.jar IS python. You need the correct version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.