Set up ScalaPy

In [1]:
import $ivy.`ai.kien::python-native-libs:0.1.0`
import ai.kien.python.Python

Python().scalapyProperties.fold(
  ex => println(s"Error while getting ScalaPy properties: $ex"),
  props => {
      props.foreach(Function.tupled(System.setProperty _))
      println(props)
  }
)
Map(jna.library.path -> /home/kien/.pyenv/versions/miniconda3-latest/lib/python3.7/config-3.7m-x86_64-linux-gnu:/home/kien/.pyenv/versions/miniconda3-latest/lib, scalapy.python.library -> python3.7m)
Out[1]:
import $ivy.$                                  

import ai.kien.python.Python

In [2]:
import $ivy.`me.shadaj::scalapy-core:0.5.0`
import me.shadaj.scalapy.py
import me.shadaj.scalapy.py.PyQuote
import me.shadaj.scalapy.py.SeqConverters
Out[2]:
import $ivy.$                              

import me.shadaj.scalapy.py

import me.shadaj.scalapy.py.PyQuote

import me.shadaj.scalapy.py.SeqConverters

Enable display of rich representations (image, html, ...) for Python objects

In [3]:
// import $ivy.`sh.almond::almond-scalapy:...`
// automatically pulled in when scalapy ivy import is detected
almond.scalapy.initDisplay

Some examples

In [4]:
val display = py.module("IPython.core.display")
Out[4]:
display: py.Module = <module 'IPython.core.display' from '/home/kien/.pyenv/versions/miniconda3-latest/lib/python3.7/site-packages/IPython/core/display.py'>
In [5]:
val img = display.Image("image.png")
In [6]:
val html = display.HTML(url = "https://google.com")
Google



 

Advanced search

© 2021 - Privacy - Terms

In [7]:
// If pandas is installed
py.module("pandas").read_csv("https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv").head(10)
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
5 5.4 3.9 1.7 0.4 setosa
6 4.6 3.4 1.4 0.3 setosa
7 5.0 3.4 1.5 0.2 setosa
8 4.4 2.9 1.4 0.2 setosa
9 4.9 3.1 1.5 0.1 setosa

Compared with almond display API

In [8]:
import almond.interpreter.api.DisplayData
Out[8]:
import almond.interpreter.api.DisplayData
In [9]:
almond.display.Image.from(new java.io.File("./image.png").toURI.toURL)
In [10]:
almond.display.Html.from("https://www.google.com")
Google



 

Advanced search

© 2021 - Privacy - Terms