I have a prototype written in Python that I need to port into Java to put into production. Python 2.7.10 has been installed using miniconda
. The prototype uses a 3rd party library nltk
that I installed using pip
.
To void rewriting the code from scratch, at least initially, I want to first try call the prototype code directly from Java using jython
.
When I try executing a command like
java -jar jython-standalone-2.7.0.jar myPrototype.py
I get
Traceback (most recent call last):
File "myPrototype.py", line 4, in <module>
from nltk import AlignedSent
ImportError: No module named nltk
It works fine when I run python myPrototype.py
.
Is there a way of configuring my jython
install so that it can find all 3rd party packages that I've added to my python
install? I realize that some of those might not run in jython
but at least I want to have access to those that do.
The bulk of NLTK is Python code so you should be able to use it from Jython as long as it's in your module search path. If you are on unix just add a link to your nltk in site-packages to the current folder. Or look into the documentation here: http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html NLTK needs to be able to load its data for some stuff. You may want to either make al link to your nltk_data from your home to the current folder or see this answer to set it from code: How to config nltk data directory from code?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.