LESSON

Importing Python Libraries

Description

In this lesson, we will learn how to import third party Python libraries into an Ignition container.

Transcript

(open in window)

[00:00] In this lesson, I'll demonstrate how to add a third party Python library into a container so that it can be imported into your scripts in Ignition. In my setup, I have a Docker Compose stack with two Ignition gateways, and I really need this "speciallibrary" python code to be able to run in my project to accomplish my project's goals. However, I haven't imported this library yet and my script errors out because the code can't be found. If we recall, we can place Python files in the "pylib" folder in the Ignition install directory in order to import them into Ignition. So, how can we do this with containers? We can accomplish this with bind mounts. I'll head over to my docker compose file and I'll add a new volume to my frontend gateway. I already have a folder that contains my script inside my project folder. All I need to do is add this Python file to the bind mount and I'll mount it to the "pylib" folder in my container, which on Linux is in "usr/local/bin /ignition/userlib/pylib". Now that the mount is set up, I'll save and I can start the container again, and it will apply the changes.

[01:15] I'll reopen my project. reopen the script console and I can paste my code. And now it runs and I can move forward with my project.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.