Dify平台插件手动安装

Dify平台的所有插件是在一个名叫docker-plugin_daemon-1的docker容器内进行管理的。

坑点

  • Dify 1.14.2 的 .venv 使用了 系统 Python 解释器,但 site-packages 路径没有正确配置。如果直接在容器内执行pip install -r requirements.txt,则pip 安装时把包装到了系统路径,而不是 .venvsite-packages
  • 先将老的插件删除掉,再去安装你的目标插件。

直接安装到 .venv 的 site-packages

# 进入容器
docker exec -it docker-plugin_daemon-1 bash

# 进入插件目录
cd /app/storage/cwd/langgenius/tongyi-0.2.16@6a3bfd05067f9a146457e882847673b53cc6681707a172f800ceed4070b231a7

# 直接用 .venv 的 python 安装,指定目标路径
.venv/bin/python -m pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages
.venv/bin/python -m pip install cryptography -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages
.venv/bin/python -m pip install gevent -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages
.venv/bin/python -m pip install aiohttp -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages
.venv/bin/python -m pip install pydantic-core -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages
.venv/bin/python -m pip install openai -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages
.venv/bin/python -m pip install dashscope -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages
.venv/bin/python -m pip install tiktoken -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages

# 安装剩余依赖
.venv/bin/python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir --target .venv/lib/python3.12/site-packages

# 验证
ls .venv/lib/python3.12/site-packages/ | head -20

exit

# 重启
docker restart docker-plugin_daemon-1

或者:使用 uv 安装(Dify 1.14.2 原生支持)

如果你发现目录下有 uv.lock 文件,说明 Dify 使用 uv 管理依赖:

# 进入容器
docker exec -it docker-plugin_daemon-1 bash

cd /app/storage/cwd/langgenius/tongyi-0.2.16@6a3bfd05067f9a146457e882847673b53cc6681707a172f800ceed4070b231a7

# 设置清华源
export UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple

# 安装依赖
uv pip install -r requirements.txt --python .venv/bin/python --no-cache

exit

# 重启
docker restart docker-plugin_daemon-1

如果重启容器之后,发现Dify界面上仍显示需要更新插件,可采用如下方式强制跳过。

# 进入容器
docker exec -it docker-plugin_daemon-1 bash

cd /app/storage/cwd/langgenius/tongyi-0.2.16@6a3bfd05067f9a146457e882847673b53cc6681707a172f800ceed4070b231a7

# 创建一个标记文件,让 Dify 认为依赖已安装
touch .venv/.installed

exit
docker restart docker-plugin_daemon-1