简体   繁体   English

使用jython的java有错误的python版本

[英]java using jython has wrong python version

Im trying to use java to run a python function through jython.jar. 我试图通过jython.jar使用java来运行python函数。 I'm using a python module that is downloaded from web which needs python 2.6 or higher. 我正在使用从web下载的python模块,需要python 2.6或更高版本。 I'm pretty sure that my python is version 2.7.2. 我很确定我的python是2.7.2版本。 However, when I try to run the java program, it continues to report python 2.5 detected. 但是,当我尝试运行java程序时,它会继续报告检测到的python 2.5。 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

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 你需要使用Jython 2.7b3,2.7 beta增加了与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. 2.7测试版4将在7月份发布,之后将会冻结功能。 I suggest you join the python-dev mailing list to stay aware of new releases. 我建议你加入python-dev邮件列表以了解新版本。 Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM