Java using jython has the wrong version of python

I am trying to use java to run a python function through jython.jar. I am using a python module that downloads from the internet, which requires python 2.6 or higher. I am sure my python is version 2.7.2. However, when I try to run a java program, it continues to report python 2.5 detection. How can i solve 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:

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
+4
source share
1 answer

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

2.7 beta 4 , . python-dev, . ,

+2

Source: https://habr.com/ru/post/1546359/


All Articles