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.
- Run the following command to install the PyMySQL dependency to the local /tmp/pymysql directory.
pip install PyMySQL --root /tmp/pymysql
- Run the following command to access the specified directory.
cd /tmp/pymysql/
- 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
- For details about how to use Python to develop an event function, see Developing a Python Event Function.
- For details about how to create a Python function dependency, see Creating a Dependency for a Python Function.
- For more information about function development, such as the supported runtimes, trigger events, function project packaging specifications, and DLL referencing, see Function Development Overview.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot