If you're writing protocols in our Python API, and you want to take advantage of the full power of Python, you might want to import some code from a package outside Python's standard library.

The package could be one of the great packages already made by the Python community, or one you wrote yourself.

Currently, this is an advanced task. You should be comfortable with the command line to do it.

Installing a package from the Python community

  1. SSH into your OT-2.
  2. Use pip to install the package from PyPI.

Then, you can upload protocols that import and use the package.

Installing a self-written Python package

If you have a set of functions or variables that you use often, you might want to consider creating your own Python package. This will save you the need to rewrite them. All you need to do is import the module into a protocol similar to how you would a third-party Python package.

We advise using a text editor to create the module on your computer. The OT-2 is limited to command-line editors which makes it difficult to write complex or long modules.

Once the package is written you will then need to set up the python module on the OT-2. There are two ways to do this:

  1. Build it into a module and then install it onto the OT-2 the same way you would an external package.
  2. Transfer the raw files onto the OT-2 by using SCP to some path and add that path to your import paths in your protocol.

Can I upload protocols comprising multiple Python files through the Opentrons App?

Not currently.

Instead, write your protocol so that it's a single self-contained Python file.

Or, as described above, collect your additional files into a package, and use pip to install it.

Troubleshooting

Certain packages can't be installed

Some of the more sophisticated Python packages, like NumPy, aren't written purely in Python. Parts of them are written in other languages, like C.

You won't be able to install those packages on the OT-2. They require a compiler, which the OT-2 doesn't have. If you try, you'll see an error like this:

compilation terminated
error: command 'get' failed with exit status 1


If one of these packages is critical to your workflow, you can ask us to include it on all OT-2s by default, starting with the next software update.

First, please search our Github repository issues to see if someone else has already requested that Python package. If they have, please thumbs-up their issue instead of making a new one.

Otherwise, you can make a new issue to request the package. In the issue, please tell us a little bit about how you plan on using the package and why it's necessary. This will help our software engineers fulfill the request efficiently—or suggest an alternative, if there is one.

ModuleNotFoundError

If your Python API protocol uses a third-party Python package, and you see an error like:

ModuleNotFoundError [line x]: No module named 'example'

It's probably because you're trying to use a package that's not yet installed on your OT-2. Follow the steps above to install it.

Did this answer your question?