All Products
Document Center

Function Compute:Deploy a code package

Last Updated:Feb 04, 2024

This topic describes how to install a code package in Python and package code to Function Compute. In this topic, a third-party dependency emoji is used as an example.


  1. Create a code directory for testing and specify a name for the directory. In this example, mycode is used.

    • Linux and macOS

      Run the mkdir -p /tmp/mycode command to create the directory.

    • Windows

      Create a folder and name it mycode.

  2. In the mycode directory, create the file.

    The following code describes the file content.

    from emoji import emojize
    def handler(event, context):
        return emojize(":thumbs_up:")

Use pip to install dependencies and deploy code


  • Python 3 is installed on your on-premises device, and you are granted the required permissions on pip3.

  • A Python function is created in the Function Compute console. For more information, see the "Create a function" section of the Manage functions topic.


  1. Run the pip3 install emoji -t .command in the mycode directory to install the emoji dependency library to the current directory.

  2. Package all files in the mycode directory.

    • Linux and macOS

      Go to the mycode directory and run the zip -r ./* command.


      Make sure that you have the read and write permissions on the directory.

    • Windows

      Go to the mycode directory, select all files, right-click the files, and then compress all files into a .zip file.

  3. In the Function Compute console, find the function that you want to manage. In the upper-right corner of the function details page, click Upload Code and upload the .zip file that you prepared.


Function Compute provides the Linux-driven running environment for functions. If you upload a code package of emoji to install the emoji dependency library on a Windows- or macOS-driven device and a binary file is also included in the code package, the code package fails to run. In this case, we recommend that you package your code by using WebIDE. For more information, see Use WebIDE to package third-party dependencies of a function.


You can also use the layer feature of Function Compute to install dependencies. We recommend that you use an official common layer or build a dependency layer online. For more information, see the following topics: