Install custom and conflicting dependencies.¶
When configuring your UbiOps environment you may encounter packages that do not install properly one way or another. E.g. because some packages are conflicting with each other or have broken subdependencies, or you may want to add your custom-made dependency that is not available on a pip repository. That means that you cannot install it by just using the requirements.txt
file, and therefore you will need to install it locally and upload it afterwards. This how-to
will show you how to manually install such packages into your UbiOps environment package.
This how-to
will cover the following steps:
- Preparing local environment
- Install Python 3 and other Linux packages
- Install your Python package
- Zip and upload the environment package
Use the correct local environment¶
You first need to match the Operating Systen (OS) of the base environment that you are going to use. UbiOps builds containers on Ubuntu, so you will need to work in such an environment.
This can be done in different ways, such as:
- Running a virtual machine with this OS
- Running Windows Subsystem for Linux (WSL)
- Spinning up a container with this OS image
Install the needed Python version and other Linux packages¶
You need to install the required Python 3 version for your package. This can be done in a multitude of ways, you can install from APT or from source. We will cover the first one.
First, update the package repository:
sudo apt update
Then install the Python version of the base environment that you are going to use:
sudo apt install python3.YOUR-VERSION
Your package may have Linux subdepencies that are required to install and / or to run it. To make these available in your deployment instances, you can add these to a ubiops.yaml
environment file. To make them available locally, you need to install them with e.g. apt
:
sudo apt update
sudo apt install YOUR-LINUX-PACKAGE
Install your Python package¶
We can now install the dependency to a target libraries
directory, so that it can be imported by your deployment. Find more information on this folder here.
First create the directory:
mkdir PATH/TO/UBIOPS/ENV/PACKAGE/libraries
Then install your Python package into the newly created directory with:
pip install --no-deps --target=PATH/TO/UBIOPS/ENV/PACKAGE/libraries YOUR-PYTHON-PACKAGE==YOUR-PACKAGE-VERSION
The --no-deps
flag will only install the package without the necessary dependencies. However, you will need to ensure that all subdependencies are added to the requirements.txt
file in the UbiOps environment package. The --target
flag will install the package in the specified directory. Here it needs to be under libraries
in the environment package. You can find any subdependencies of your package by running the following command and looking under the Requires:
section.
pip show YOUR-PYTHON-PACKAGE
Zip the directory of the package to the UbiOps environment¶
You can now add any additional environment files to your directory, zip it and upload it when creating a new UbiOps environment, or when updating an environment revision.
zip -r environment_package.zip PATH/TO/UBIOPS/ENV_PACKAGE/
So that's it! We have gone through a full configuration of a Python package that cannot be installed regularly in the environment package. There are more tutorials covering UbiOps environments here and here.