zeppelin/docs/interpreter/python.md

2.5 KiB

layout title description group
page Python Interpreter Python Interpreter manual

{% include JB/setup %}

Python 2 & 3 Interpreter for Apache Zeppelin

Configuration

Property Default Description
python python Path of the already installed Python binary (could be python2 or python3). If python is not in your $PATH you can set the absolute directory (example : /usr/bin/python)

Enabling Python Interpreter

In a notebook, to enable the Python interpreter, click on the Gear icon and select Python

Using the Python Interpreter

In a paragraph, use %python to select the Python interpreter and then input all commands.

The interpreter can only work if you already have python installed (the interpreter doesn't bring it own python binaries).

To access the help, type help()

Python modules

The interpreter can use all modules already installed (with pip, easy_install...)

Apply Zeppelin Dynamic Forms

You can leverage Zeppelin Dynamic Form inside your Python code. Example :

%python
# Input fom
print (z.input("f1","defaultValue"))

# Select fom
print (z.select("f1",[("o1","1"),("o2","2")],"2"))

#Checkbox form
print("".join(z.checkbox("f3", [("o1","1"), ("o2","2")],["1"])))

Matplotlib integration

The python interpreter can display matplotlib graph with the function zeppelin_show() You need to already have matplotlib module installed to use this functionality !

%python
import matplotlib.pyplot as plt
plt.figure()
(.. ..)
zeppelin_show(plt)
plt.close()

zeppelin_show function can take optional parameters to adapt graph width and height

%python
zeppelin_show(plt,width='50px')
zeppelin_show(plt,height='150px')

pythonmatplotlib

Use matplotlib without XServer

Matplotlib needs a X server to plot graph.

If you don't have any XServer and you don't want to install one (typically, a server environment) , you can use Xvfb to simulate it.

Althought Xvfb doesn't display anything, you will have any issue to use the python interpreter, matplotlib and Xvfb. The interpreter plot the graph on X and then extracts svg path (in strings) to send it to the zeppelin webapp.