Create and Use Python Environment

Runner has its own Python environment that it uses internally. Sometimes you might want to add a Python package in support of a project. You never want to add that package to the default Runner Python Environment because it could break something, leaving you with a non-functional Runner. Instead you can create a separate Python Environment and add the package to that. Then you run your Python project using the Python3 executable from that environment. You can do this via Runner jobs. Here are some sample configs.

To create the new Python environment, create a Runner CMD job to run this command:
/app/env/bin/python3 -m venv /var/mitto/data/<pyenv_name>

If you want to use a generic job, the full config will look like this:

{
shell: true
cmd: /app/env/bin/python3 -m venv /var/mitto/data/<pyenv_name>
exec: true
timeout: null
cmd_env: {
}
}

If you need to add a new Python package, you can create a Runner CMD job with this command:
/var/mitto/data/<pyenv_name>/bin/pip3 install <Python pkg>

If you want to use a generic job, the full config can include several different packages and will look something like this:

{
cmd:
‘’’
/var/mitto/data/<pyenv_name>/bin/pip3 install wheel
/var/mitto/data/<pyenv_name>/bin/pip3 install ‘https://github.com/zuarbase/python-mitto-sdk/archive/dd821d2203cb94a0b68ac0080e6263585f94589f.zip
/var/mitto/data/<pyenv_name>/bin/pip3 install requests
/var/mitto/data/<pyenv_name>/bin/pip3 install hjson
/var/mitto/data/<pyenv_name>/bin/pip3 install psutil
‘’’
cmd_env: {
}
exec: false
shell: true
}

Lastly, you can run your Python script via a third Runner CMD job created with this command:
/var/mitto/data/<pyenv_name>/bin/python3 /var/mitto/data/<scriptname>

If you want to use a generic job, the full config will look something like this:

{
shell: true
cmd: /var/mitto/data/<pyenv_name>/bin/python3 /var/mitto/data/check_cpu2.py
exec: false
timeout: null
cmd_env: {
}
}