python - 如何在 jython 中导入模块?
问题描述
我正在尝试在 Jython 中导入 Textblob 模块,但我没有收到NO MODULE WITH NAME异常。我尝试了不同的模块,但出现了相同的异常。虽然这个问题可能看起来很模糊,但这是唯一的问题。
解决方案
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')");
这就是我解决它的方法,希望它可以帮助某人:)
推荐阅读
- python - python是否有一个包或函数来训练具有堆叠自动编码器的神经网络,如R中的deepnet
- docker - 为什么我不能在不从 docker 桌面进入的情况下调用 ubuntu 容器的发布版本?
- linkedin - Marketing Developer Platform 应用审核电子邮件
- android - 如何在 Android 中格式化 DateTime 变量
- vue.js - 画布不绘制图像 - Electron + Vue
- javascript - React - 回调的关闭问题
- python - 如何打印 a 的内容?
- c# - MySql 查询无法在 2 台安装了相同软件的 PC 上运行
- java - 在客户端和应用程序之间同步数据库
- php - 我在 SQL 事务中收到未捕获的 PDO 异常错误