首页 > 解决方案 > 如何在 jython 中导入模块?

问题描述

我正在尝试在 Jython 中导入 Textblob 模块,但我没有收到NO MODULE WITH NAME异常。我尝试了不同的模块,但出现了相同的异常。虽然这个问题可能看起来很模糊,但这是唯一的问题。

标签: pythonjython

解决方案


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')");

这就是我解决它的方法,希望它可以帮助某人:)


推荐阅读