2016-05-30 20:07:26 +00:00
---
layout: page
title: "Python Interpreter"
description: "Python Interpreter"
group: manual
---
{% include JB/setup %}
2016-06-25 19:44:53 +00:00
# Python 2 & 3 Interpreter for Apache Zeppelin
< div id = "toc" > < / div >
2016-05-30 20:07:26 +00:00
## Configuration
< table class = "table-configuration" >
< tr >
< th > Property< / th >
< th > Default< / th >
< th > Description< / th >
< / tr >
< tr >
2016-06-22 22:41:16 +00:00
< td > zeppelin.python< / td >
2016-05-30 20:07:26 +00:00
< td > python< / td >
< td > 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)
< / td >
< / tr >
2016-06-22 22:41:16 +00:00
< tr >
< td > zeppelin.python.maxResult< / td >
< td > 1000< / td >
< td > Max number of dataframe rows to display.< / td >
< / tr >
2016-05-30 20:07:26 +00:00
< / table >
## 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...)
2016-06-23 01:25:49 +00:00
## Use Zeppelin Dynamic Forms
2016-05-30 20:07:26 +00:00
You can leverage [Zeppelin Dynamic Form ]({{BASE_PATH}}/manual/dynamicform.html ) inside your Python code.
**Zeppelin Dynamic Form can only be used if py4j Python library is installed in your system. If not, you can install it with `pip install py4j` .**
Example :
```python
%python
### Input form
print (z.input("f1","defaultValue"))
### Select form
print (z.select("f1",[("o1","1"),("o2","2")],"2"))
### Checkbox form
print("".join(z.checkbox("f3", [("o1","1"), ("o2","2")],["1"])))
```
## Zeppelin features not fully supported by the Python Interpreter
* Interrupt a paragraph execution (`cancel()` method) is currently only supported in Linux and MacOs. If interpreter runs in another operating system (for instance MS Windows) , interrupt a paragraph will close the whole interpreter. A JIRA ticket ([ZEPPELIN-893](https://issues.apache.org/jira/browse/ZEPPELIN-893)) is opened to implement this feature in a next release of the interpreter.
* Progression bar in webUI (`getProgress()` method) is currently not implemented.
* Code-completion is currently not implemented.
## Matplotlib integration
2016-06-23 01:25:49 +00:00
The python interpreter can display matplotlib graph with the function `z.show()` .
2016-06-16 15:50:06 +00:00
You need to have matplotlib module installed and a XServer running to use this functionality !
2016-05-30 20:07:26 +00:00
```python
%python
import matplotlib.pyplot as plt
plt.figure()
(.. ..)
2016-06-23 01:25:49 +00:00
z.show(plt)
2016-05-30 20:07:26 +00:00
plt.close()
```
2016-06-23 22:22:41 +00:00
z.show function can take optional parameters to adapt graph width and height
2016-05-30 20:07:26 +00:00
```python
%python
2016-06-23 01:25:49 +00:00
z.show(plt, width='50px')
z.show(plt, height='150px')
2016-05-30 20:07:26 +00:00
```
2016-06-25 19:44:53 +00:00
< img class = "img-responsive" src = "../assets/themes/zeppelin/img/docs-img/pythonMatplotlib.png" / >
2016-05-30 20:07:26 +00:00
2016-06-23 01:25:49 +00:00
## Pandas integration
[Zeppelin Display System ]({{BASE_PATH}}/displaysystem/basicdisplaysystem.html#table ) provides simple API to visualize data in Pandas DataFrames, same as in Matplotlib.
Example:
```python
import pandas as pd
rates = pd.read_csv("bank.csv", sep=";")
z.show(rates)
```
2016-06-16 15:50:06 +00:00
## Technical description
2016-05-30 20:07:26 +00:00
2016-06-25 19:44:53 +00:00
For in-depth technical details on current implementation plese reffer [python/README.md ](https://github.com/apache/zeppelin/blob/master/python/README.md ).