Dify平台的所有插件是在一个名叫docker-plugin_daemon-1的docker容器内进行管理的。
坑点:
- Dify 1.14.2 的
.venv 使用了 系统 Python 解释器,但 site-packages 路径没有正确配置。如果直接在容器内执行pip install -r requirements.txt,则pip 安装时把包装到了系统路径,而不是 .venv 的 site-packages。
- 如果是安装同一类型的插件,建议先将旧的插件删除掉,再去安装你的目标插件。
直接安装到 .venv 的 site-packages
docker exec -it docker-plugin_daemon-1 bash
cd /app/storage/cwd/langgenius/tongyi-0.2.16@6a3bfd05067f9a146457e882847673b53cc6681707a172f800ceed4070b231a7
.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
touch .venv/.installed
exit docker restart docker-plugin_daemon-1
|
一劳永逸:在.env中添加环境变量UV_INDEX_URL
cd /path/to/dify/docker nano .env
|
添加:
PLUGIN_MAX_EXECUTION_TIMEOUT=300
UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
|
然后在 docker-compose.yaml 的 plugin-daemon 中引用:
services: plugin-daemon: image: langgenius/dify-plugin-daemon:0.6.1-local restart: always environment: PLUGIN_MAX_EXECUTION_TIMEOUT: ${PLUGIN_MAX_EXECUTION_TIMEOUT:-300} UV_INDEX_URL: ${UV_INDEX_URL:-https://pypi.org/simple}
|
操作步骤:
cd /path/to/dify/docker
cp docker-compose.yaml docker-compose.yaml.bak
nano docker-compose.yaml
docker compose down docker compose up -d
|
验证配置是否生效:
docker exec -it docker-plugin_daemon-1 bash
echo $UV_INDEX_URL
exit
|