如何在Google Colab中使用Java

时间:2018-07-11 13:51:26

标签: java python stanford-nlp google-colaboratory

我想在我的Google Colab Notebook中使用Stanford CoreNLP。为此,我需要Java。有没有办法在这些机器上安装Java?

我目前拥有的是:

!pip install StanfordCoreNLP
from stanfordcorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP('stanford-corenlp', lang='de', memory='4g')
...
nlp.close()

我得到了错误:

FileNotFoundError: [Errno 2] No such file or directory: 'java': 'java'

1 个答案:

答案 0 :(得分:5)

尝试

import os       #importing os to set environment variable
def install_java():
  !apt-get install -y openjdk-8-jdk-headless -qq > /dev/null      #install openjdk
  os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"     #set environment variable
  !java -version       #check java version
install_java()