You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Appwrite函数构建失败:指定依赖版本仍无法正常安装

解决Appwrite函数部署时numpy/pandas安装失败的问题

问题根源

Appwrite函数的运行环境基于Alpine Linux(使用musl libc),而numpy、pandas这类依赖在musl环境下源码编译容易失败——要么缺少编译依赖,要么部分版本没有预编译的musl兼容wheels,导致pip尝试从源码编译时出错。

方案1:用Python标准库替代pandas(推荐)

你的需求只是将CSV转为JSON的records格式,完全可以用Python标准库的csv和json模块实现,无需依赖numpy和pandas,彻底避免编译问题。修改后的函数代码如下:

from appwrite.client import Client
from appwrite.services.storage import Storage
import csv
import json
from io import BytesIO

def main(req, res):
    file_id = res.payload["fileId"]
    bucket_id = res.variables.BUCKET_ID
    api_key = res.variables.API_KEY
    
    client = Client()
    client.set_endpoint(res.variables.ENDPOINT)
    client.set_project(res.variables.PROJECT_ID)
    client.set_key(api_key)
    
    storage = Storage(client)
    binary_csv = storage.get_file_view(bucket_id, file_id)
    data = BytesIO(binary_csv)
    
    # 用标准库解析CSV
    csv_reader = csv.DictReader(data.read().decode('utf-8').splitlines())
    json_data = json.dumps(list(csv_reader))
    
    return res.json({
        "message": "Success <200>",
        "payload": json_data
    })

同时修改requirements.txt,只保留必要的依赖:

appwrite

方案2:调整依赖版本,使用兼容musl的预编译包

如果一定要用pandas,可以指定有musl预编译wheels的版本,避免源码编译。修改requirements.txt为:

appwrite
numpy==1.23.5
pandas==1.5.3

这些版本的numpy和pandas提供了musl兼容的预编译wheels,pip可以直接下载安装,无需编译。

另外,也可以在部署时添加pip参数强制使用预编译包(如果你的Appwrite支持自定义pip命令),比如在部署配置中执行:

pip install --only-binary :all: -r requirements.txt

额外注意点

  • 确保你的Appwrite函数使用的Python版本和本地一致(日志显示当前用的是Python 3.10),版本不匹配也可能导致依赖安装问题。
  • 函数环境变量配置错误不影响本次构建失败,但后续运行需确认配置正确。

内容的提问来源于stack exchange,提问作者Mathieu Sherburne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 00:41:38