背景
这两年公司降本增效,裁了一大波人,导致一个人要身兼数职。之前系统工程师在现场部署了 Dify 并装了一些插件,最近发现 OpenAI-API-compatible 插件异常,可能需要重装。问了下工程师,对方表示"没时间,你们自己装一下,步骤很简单:1. 下载插件导入;2. 默认安装要联网下 Python 包,现在可能缺依赖,看插件容器的日志,只能把依赖一个个导进去"。
我一个纯小白,连 Python 依赖是什么都说不清楚,硬着头皮上吧。服务器在内网,不联网,只能走本地插件安装方式。
过程记录
1. 下载插件 & 初次尝试
去 marketplace 下载了老版本 0.0.3,得到文件 langgenius-openai_api_compatible_0.0.3.difypkg。在 Dify 后台选择本地插件上传,等了一会儿提示失败。查看容器日志:
bash
docker logs dify-plugin_daemon-1
报错:
arduino
Collecting dify_plugin~=0.0.1b61 (from -r requirements.txt (line 1))
Could not find a version that satisfies the requirement dify_plugin~=0.0.1b61 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for dify_plugin~=0.0.1b61 (from -r requirements.txt (line 1))
Pip download failed.
一看就知道是因为没法联网下载依赖。内网环境,这也在意料之中,但没想到连基础依赖都没有预置。
2. 手动打包依赖
工程师说的"把依赖一个个导进去"听起来简单,做起来真是磨人。先找了个打包工具:
arduino
https://github.com/junjiem/dify-plugin-repackaging
把下载好的依赖放到 langgenius-openai_api_compatible_0.0.3 目录下的 wheels 中,然后打包:
bash
./plugin_repackaging.sh local ./langgenius-openai_api_compatible_0.0.3.difypkg
得到 offline 包:/app/output/langgenius-openai_api_compatible_0.0.3-offline.difypkg。上传后提示签名不对。查了一下,需要在 docker-compose.yaml 里加:
ini
FORCE_VERIFYING_SIGNATURE=false
加上后能上传了,但日志又报新错误:
ini
2026/06/09 16:45:29 runtime_lifetime.go:86: [ERROR]init environment failed: failed to install dependencies: exit status 1, output: × No solution found when resolving dependencies:
╰─▶ Because socksio was not found in the provided package locations and
dify-plugin==0.0.1b61 depends on socksio==1.0.0, we can conclude that
dify-plugin==0.0.1b61 cannot be used.
And because only dify-plugin==0.0.1b61 is available and you require
dify-plugin==0.0.1b61, we can conclude that your requirements are
unsatisfiable.
, retry in 30s
缺 socksio。我当时以为只缺这一个,下载 socksio.whl 重新打包,上传,又缺另一个。反反复复三四次,每次都是加一个依赖、打包、上传、再报缺另一个。整个人快麻了,感觉像个无底洞。
3. 一次性下载所有依赖
后来大模型提了一嘴:"你可以一次性把所有依赖都下载下来。" 我才反应过来------对啊,我之前怎么就没想到呢?一直被报错牵着鼻子走,一个一个地补,蠢死了。
于是新建 requirements.txt,内容只有一行:
ini
dify-plugin==0.0.1b61
在有网的机器上执行:
bash
pip download \
-r requirements.txt \
-d ./wheels \
--pre \
--only-binary=:all: \
--python-version 3.12 \
--platform manylinux2014_x86_64 \
--implementation cp \
--abi cp312
命令跑完,./wheels 里自动下载了所有依赖(包括 dify-plugin、socksio 以及它们的子依赖)。然后把整个 wheels 目录放进插件目录,重新打包。这一步总算解决了依赖不全的问题。
4. 文件大小超限
打包出来的 offline 插件包超过了 15MB,Dify 默认限制上传大小。修改 docker-compose.yaml:
yaml
PLUGIN_MAX_PACKAGE_SIZE: ${PLUGIN_MAX_PACKAGE_SIZE:-52428800}
NGINX_CLIENT_MAX_BODY_SIZE: ${NGINX_CLIENT_MAX_BODY_SIZE:-100M}
UPLOAD_FILE_SIZE_LIMIT: ${UPLOAD_FILE_SIZE_LIMIT:-100}
重启服务:
bash
docker compose down && docker compose up -d
再次上传,仍然提示文件过大。检查 Nginx 配置:
bash
docker exec -it dify-nginx-1 nginx -T | grep client_max_body_size
# 输出: client_max_body_size 15M;
docker exec -it dify-nginx-1 env | grep NGINX_CLIENT_MAX_BODY_SIZE
# 输出: NGINX_CLIENT_MAX_BODY_SIZE=15M
明明环境变量改成了 100M,实际还是 15M。我搜了半天:
bash
grep -r "15M" . --include="*.conf" --include="*.template" --include="*.yml" --include="*.env"
发现有一个隐藏的 .env 文件里写死了 NGINX_CLIENT_MAX_BODY_SIZE=15M。改掉这个文件,再重启,终于能上传了。当时真是又好气又好笑------没想到被一个隐藏文件卡了这么久。
5. 最终成功
查看插件容器日志:
bash
2026/06/10 09:39:18 runtime_lifetime.go:48: [INFO]new plugin logged in: langgenius/openai_api_compatible:0.0.3
2026/06/10 09:39:18 runtime_lifetime.go:80: [INFO]init environment for plugin langgenius/openai_api_compatible:0.0.3
2026/06/10 09:39:20 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Listing '.'......
2026/06/10 09:39:20 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Listing './.venv/lib/python3.12/site-packages/dify_plugin/config'......
2026/06/10 09:39:21 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/dify_plugin/interfaces/model/rerank_model.py'......
2026/06/10 09:39:21 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/dpkt/tftp.py'......
2026/06/10 09:39:22 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/gevent/testing/errorhandler.py'......
2026/06/10 09:39:22 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/gevent/tests/test__issue330.py'......
2026/06/10 09:39:23 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/greenlet/tests/fail_switch_three_greenlets.py'......
2026/06/10 09:39:23 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/idna/intranges.py'......
2026/06/10 09:39:24 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/pydantic/errors.py'......
2026/06/10 09:39:25 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/requests/models.py'......
2026/06/10 09:39:25 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/werkzeug/middleware/__init__.py'......
2026/06/10 09:39:25 environment_python.go:287: [INFO]pre-compiling langgenius/openai_api_compatible:0.0.3 - Compiling './.venv/lib/python3.12/site-packages/zope/interface/tests/test_advice.py'......
2026/06/10 09:39:25 environment_python.go:320: [INFO]pre-loaded the plugin langgenius/openai_api_compatible:0.0.3
2026/06/10 09:39:28 run.go:143: [INFO]plugin langgenius/openai_api_compatible:0.0.3 started
日志没有报错,插件正常启动了。折腾了两天,终于可以用了。
最简解决问题
若要在内网环境 离线安装 Dify 插件(以 openai_api_compatible 为例),请按以下步骤操作:
- 下载插件包 (例如
langgenius-openai_api_compatible_0.0.3.difypkg)。 - 解包,收集依赖 :
-
创建
requirements.txt,写入dify-plugin==0.0.1b61。 -
在有网机器上执行:
bashpip download -r requirements.txt -d ./wheels --pre --only-binary=:all: --python-version 3.12 --platform manylinux2014_x86_64 --implementation cp --abi cp312 -
将
./wheels目录放入解包后的插件目录中。
-
- 重新打包 :使用
dify-plugin-repackaging工具打包为-offline.difypkg。 - 修改 Dify 配置 :
docker-compose.yaml中设置FORCE_VERIFYING_SIGNATURE=false(跳过签名验证)。- 增大上传限制:设置
PLUGIN_MAX_PACKAGE_SIZE、NGINX_CLIENT_MAX_BODY_SIZE、UPLOAD_FILE_SIZE_LIMIT为足够大的值(如 100M)。 - 注意 :检查是否有隐藏
.env文件覆盖了NGINX_CLIENT_MAX_BODY_SIZE,需一并修改。
- 重启 Dify 服务 :
docker compose down && docker compose up -d。 - 上传离线插件包,安装即可。
总结
只能说这个时代幸好有大模型辅助解决问题,不然真的麻烦了,学知识慢,解决问题也需要依靠大量的经验,小白更是寸步难行,现在也是方便了很多。不过这个时代也挺难的,以后开发工程师要懂得更多,解决得问题要更好更快,真正需要降本增效啊。