This article covers the importing of a Python package that we don't have installed on Mitto, such as pandas or NumPy. In this case, we need to use a virtual environment. The virtual environment will need to be created manually on your Mitto before this will work. In this case I created a new directory in /var/mitto/data/
called testenv
, then I ran virtualenv -p /usr/bin/python3 testenv/
, then source testenv/bin/activate
, and finally I used pip to install pandas and numpy.
With my virtual environment set up, the following script creates a small dataframe and writes it to a file at: /var/mitto/data/also_written_by_python.txt
.
import numpy as np
import pandas as pd
s = pd.Series([1, 3, 5, np.nan, 6, 8])
f = open("/var/mitto/data/also_written_by_python.txt", "w")
f.write(str(s))
f.close()
In order to run this script via the virtual environment, we'll execute it using python
from our virtual environment like this:
{
"cmd": "/var/mitto/data/testenv/bin/python /var/mitto/data/python_test.py",
"shell": true
}
The resulting file should look like this:
$ cat also_written_by_python.txt
0 1.0
1 3.0
2 5.0
3 NaN
4 6.0
5 8.0