All Products
Search
Document Center

Function Compute:Deploy a code package

Last Updated:Apr 01, 2026

Install third-party dependencies for your Python function, package the code, and deploy it to Function Compute. This guide uses the emoji library as a working example.

Choose a deployment method

MethodBest forRequires
pip + console uploadPure-Python dependencies (no compiled binaries)Python 3, pip3
Serverless Devs + DockerDependencies with binary extensions (C/C++, cryptography, numpy, etc.)Serverless Devs CLI, Docker

If your dependencies include compiled binary files, use the Serverless Devs method. Binary files built on macOS or Windows are incompatible with the Linux environment that Function Compute runs in.

Preparations

Set up a local code directory and a sample function before following either method.

  1. Create a directory named mycode.

    • Linux and macOS: mkdir -p /tmp/mycode

    • Windows: Create a folder named mycode

  2. In the mycode directory, create index.py with the following content:

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

Method 1: Use pip and the console

Prerequisites

Before you begin, make sure you have:

Install dependencies and upload

  1. Install the emoji dependency into the mycode directory:

    pip3 install emoji -t .

    Run this command from inside the mycode directory. The -t . flag installs the package into the current directory instead of the global site-packages.

  2. Package all files in mycode into a ZIP file.

    • Linux and macOS: Go to the mycode directory and run:

      zip code.zip -r ./*
      Note

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

    • Windows: Select all files in the mycode directory, right-click, and compress them into a .zip file.

  3. Upload the ZIP file in the Function Compute console:

    1. Locate the target function and go to its Function Details page.

    2. Click the Code tab.

    3. Click Upload Code > Upload ZIP Package, then select code.zip.

    4. Click Save and Deploy.

Important

Function Compute runs in a Linux environment. If the emoji library (or any other dependency) contains compiled binary files, the package may fail to run when installed on macOS or Windows. In that case, we recommend that you use WebIDE to package third-party dependencies or use Method 2 (Serverless Devs + Docker).

Method 2: Use Serverless Devs and Docker

Serverless Devs builds dependencies inside a Docker container that matches the Function Compute Linux runtime, ensuring binary compatibility.

Prerequisites

Before you begin, make sure you have:

Build and deploy

  1. Go to the mycode directory:

    cd /tmp/mycode
  2. Create s.yaml with the following content:

    edition: 3.0.0
    name: fcDeployApp
    access: "default"
    
    vars: # The global variables.
      region: "cn-hangzhou"
    
    resources:
      hello_world:
        component: fc3 # The name of the component.
        props:
          region: ${vars.region}
          functionName: "emojipy"
          description: 'this is emoji'
          runtime: "python3"
          code: ./
          handler: index.handler
          memorySize: 128
          timeout: 30
          environmentVariables:
            PYTHONUSERBASE: /code/python  # Add environment variables to obtain dependencies.code.

    The following table describes the key files in this project:

    FilePurposeRequired
    s.yamlServerless Devs project configurationYes
    index.pyFunction handler codeYes
    requirements.txtPython dependencies to installYes
  3. Create requirements.txt with the following content:

    emoji==2.0.0
  4. Build the dependencies inside a Docker container:

    sudo s build --use-docker

    After the build completes, dependencies are installed to the ./python directory.

  5. Deploy the function:

    sudo s deploy

    After deployment, the function is available in Function Compute.

What's next

Use Function Compute layers to share dependencies across multiple functions without bundling them in each code package: