Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Java in Google Colab

I want to use Stanford CoreNLP in my Google Colab Notebook. For that I need Java. Is there a way to install Java on those machines?

What I currently have is:

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

and I get the error:

FileNotFoundError: [Errno 2] No such file or directory: 'java': 'java'
like image 812
Sören Etler Avatar asked Jul 11 '18 13:07

Sören Etler


People also ask

Can I use Java on Google Colab?

Although geared and promoted predominantly as a tool for writing Python, adding a Java Kernel to Google Colab is actually pretty simple. Below is an example, using IJava. Assuming you know how to create a new account, and can navigate creating a new notebook… Edit the '.

Is Google colab only for Python?

The Basics. Colaboratory, or “Colab” for short, is a product from Google Research. Colab allows anybody to write and execute arbitrary python code through the browser, and is especially well suited to machine learning, data analysis and education.

Is there Jupyter notebook for Java?

Jupyter notebooks are extremely popular in the Python world, simply because it is great to combine documentation and code in a visually appealing way. Great tool for teaching! Thanks to the IJava kernel and the JDK 9+ JShell feature, it is possible to run Java within Notebooks without compiling the code now as well.

How do I run code on Google Colab?

To run the code in any cell, you can click the run button on the left side of the code cell (looks like a “play” button with a triangle in a circle) or you can click [shift] + [enter]. The output will appear right below the code cell. You can import many popular libraries without having to install them first.

Can we do machine learning in Google Colab?

Because your system's configurations don't matter AT ALL! With Colab, you can train your complex machine learning and deep learning models without worrying about the computational resources they require. GPUs and even much more expensive TPUs are provided by the platform free of cost!


1 Answers

try this

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()
like image 154
Sanjeev v Avatar answered Sep 22 '22 05:09

Sanjeev v