setting import module path in Jython - strange behavior

人盡茶涼 提交于 2019-12-03 16:21:24

Here is code for setting registry python.path value with user.dir in your code (Plan B I mentioned in the question):

Here is how you initialize PySysState:

props = setDefaultPythonPath(props);
PySystemState.initialize( System.getProperties(), props, null );

setDefaultPythonPath method:

/**
 * Adds user.dir into python.path to make Jython look for python modules in working directory in all cases
 * (both standalone and not standalone modes)
 * @param props
 * @return props
 */
private Properties setDefaultPythonPath(Properties props) {
    String pythonPathProp = props.getProperty("python.path");
    String new_value;
    if (pythonPathProp==null)
    {
        new_value  = System.getProperty("user.dir");
    } else {
        new_value = pythonPathProp +java.io.File.pathSeparator + System.getProperty("user.dir") + java.io.File.pathSeparator;
    }
    props.setProperty("python.path",new_value);
    return props;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!