简体   繁体   English

如何在 jython 中导入模块?

[英]How to import module in jython?

I am trying to import the Textblob module in Jython, but I am getting NO MODULE WITH NAME exception.我正在尝试在 Jython 中导入 Textblob 模块,但我没有收到NO MODULE WITH NAME异常。 I have tried different modules but the same exception appears.我尝试了不同的模块,但出现了相同的异常。 Though this question may seem vague thats the only problem.虽然这个问题可能看起来很模糊,但这是唯一的问题。

Properties p = new Properties();
        p.setProperty("python.console.encoding", "UTF-8");
        PySystemState systemState = Py.getSystemState();
        systemState.path.append(new PyString("C:\\jython2.7.1\\Lib")); 
        systemState.path.append(new PyString("C:\\jython2.7.1\\Lib\\site-packages"));
        systemState.path.append(new PyString("C:\\jython2.7.1\\pkgs"));

        PythonInterpreter.initialize(System.getProperties(), p, new String[] {});
        PythonInterpreter python = new PythonInterpreter();


        python.exec("from nltk.corpus import stopwords\ncachedStopWords = stopwords.words('english')");

This is how I solved it,Hope it helps someone:)这就是我解决它的方法,希望它可以帮助某人:)

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

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