Help Center/ FunctionGraph/ Developer Guide/ Python/ Creating a Dependency for a Python Function
Updated on 2025-12-10 GMT+08:00

Creating a Dependency for a Python Function

You are advised to create function dependencies in Huawei Cloud EulerOS 2.0. If other OSs are used, the dynamic link library may not be found due to the differences between underlying dependency libraries.

Constraints

If the modules to be installed need dependencies such as .dll, .so, and .a, archive them to a .zip package.

Setting Up the EulerOS Environment

You are advised to create function dependencies in EulerOS. EulerOS is an enterprise-grade Linux OS based on open-source technology. It features high security, scalability, and performance, meeting customers' requirements for IT infrastructure and cloud computing services.

You can set up the Huawei Cloud EulerOS environment using the following methods:

  • Buy a EulerOS ECS on Huawei Cloud by referring to Purchasing and Logging In to a Linux ECS. On the Configure Basic Settings page, select Public Image, and select Huawei Cloud EulerOS and an image version.
  • Download the EulerOS image, and use virtualization software to set up the EulerOS VM on a local PC.

Creating a Dependency for a Python Function

Before creating a dependency, ensure that Python matching the function runtime has been installed in the environment.

The following uses Python 3.12 as an example to describe how to create a PyMySQL dependency.

  1. Run the following command to install the PyMySQL dependency to the local /tmp/pymysql directory.

    pip install PyMySQL --root /tmp/pymysql

  2. Run the following command to access the specified directory.

    cd /tmp/pymysql/

  3. Go to the site-packages directory (generally lib/python3.12/site-packages/). If no dependency file exists in this directory, run the find command to find the file and go to its directory. Then run the following command to compress the dependency file.

    The required dependency is generated.

    zip -rq pymysql.zip *

To install the local wheel installation package, run the following commands:

pip install piexif-1.1.0b0-py2.py3-none-any.whl --root /tmp/piexif   
//Replace piexif-1.1.0b0-py2.py3-none-any.whl with the actual installation package name.

Helpful Links