[报错] Dify - 踩坑笔记

文章目录

      • [使用 poetry 环境](#使用 poetry 环境)
      • anthropic.types.beta.tools
      • [opendal - ConfigInvalidError](#opendal - ConfigInvalidError)
      • [extension - FileNotFoundError](#extension - FileNotFoundError)

使用 poetry 环境

dify api 不分,使用 poetry 管理环境;

使用官方配置的环境,将会更大程度的避免第三方库的各种问题

1、安装 poetry

shell 复制代码
pip install poetry

2、在 api 中安装环境

已有 .toml 文件,所以安装包就行

shell 复制代码
poetry install

环境将被安装到 .venv


3、激活环境

shell 复制代码
source /Users/.../repos/dify/api/.venv/bin/activate 

在这个环境下运行 flask run --host 0.0.0.0 --port=5001 --debug 就能解决大部分模块缺失、版本问题

使用 vscode 调试的时候,选中 /Users/.../repos/dify/api/.venv/bin/python 这个解释器


anthropic.types.beta.tools

ModuleNotFoundError: No module named 'anthropic.types.beta.tools'

使用本地 python 环境运行项目时,会报这个错误
pip install anthropic 后也无法解决,可能是版本问题

解决方法;在 api 中,使用 poetry 创建的环境,可以避免这个问题


opendal - ConfigInvalidError

shell 复制代码
发生异常: ConfigInvalidError
ConfigInvalid (permanent) at  => root is not specified
  File "/Users/pc087/Documents/repos/dify/api/extensions/storage/opendal_storage.py", line 38, in __init__
    self.op = opendal.Operator(scheme=scheme, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pc087/Documents/repos/dify/api/extensions/ext_storage.py", line 31, in <lambda>
    return lambda: OpenDALStorage(dify_config.OPENDAL_SCHEME)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pc087/Documents/repos/dify/api/extensions/ext_storage.py", line 19, in init_app
    self.storage_runner = storage_factory()
                          ^^^^^^^^^^^^^^^^^
  File "/Users/pc087/Documents/repos/dify/api/extensions/ext_storage.py", line 138, in init_app
    storage.init_app(app)
  File "/Users/pc087/Documents/repos/dify/api/app_factory.py", line 87, in initialize_extensions
    ext.init_app(app)
  File "/Users/pc087/Documents/repos/dify/api/app_factory.py", line 25, in create_app
    initialize_extensions(app)
  File "/Users/pc087/Documents/repos/dify/api/app.py", line 37, in <module>
    app = create_app()
          ^^^^^^^^^^^^
opendal.ConfigInvalidError: ConfigInvalid (permanent) at  => root is not specified

解决方法: 设置 root 地址

shell 复制代码
# self.op = opendal.Operator(scheme=scheme, **kwargs)
self.op = opendal.Operator(scheme=scheme, root='/tmp/dify')

macOS 上位于 /private/tmp/dify


extension - FileNotFoundError

shell 复制代码
发生异常: FileNotFoundError
[Errno 2] No such file or directory: '/Users/pc087/Documents/repos/dify/core/moderation'
  File "/Users/pc087/Documents/repos/dify/api/core/extension/extensible.py", line 51, in scan_extensions
    for subdir_name in os.listdir(current_dir_path):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pc087/Documents/repos/dify/api/core/extension/extension.py", line 16, in init
    self.__module_extensions[module.value] = m.scan_extensions()
                                           ^^^^^^^^^^^^^^^^^^^
  File "/Users/pc087/Documents/repos/dify/api/extensions/ext_code_based_extension.py", line 6, in init_app
    code_based_extension.init()
  File "/Users/pc087/Documents/repos/dify/api/app_factory.py", line 87, in initialize_extensions
    ext.init_app(app)
  File "/Users/pc087/Documents/repos/dify/api/app_factory.py", line 25, in create_app
    initialize_extensions(app)
  File "/Users/pc087/Documents/repos/dify/api/app.py", line 37, in <module>
    app = create_app()
          ^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/Users/pc087/Documents/repos/dify/core/moderation'

在终端运行 flask run --host 0.0.0.0 --port=5001 --debug 时没有报错;

将 dify 文件夹,拖拽到 VSCode 后,运行 app.py 文件会报错

原因:环境错误

解决方法:将 Dify 下的 api 文件拖拽到 VS Code 运行



2025-01-14(二)

相关推荐
麦麦大数据2 小时前
F004 新闻可视化系统爬虫更新数据+ flask + mysql架构
爬虫·mysql·flask·可视化·新闻
S01d13r13 小时前
gunicorn + flask 处理高并发请求
python·flask·gunicorn
千层冷面1 天前
Flask ORM 查询详解:Model.query vs db.session.query vs db.session.execute
数据库·python·django·flask
Xi_Xu1 天前
Xget:为您的开发工作流解锁极致速度
javascript·api
java1234_小锋1 天前
[免费]基于Python的影视数据可视化分析系统(Flask+echarts)【论文+源码+SQL脚本】
python·信息可视化·flask·python影视分析·python电影分析
阿湯哥2 天前
SkyPilot 的产生背景
后端·python·flask
肖祥2 天前
Langfuse-开源AI观测分析平台,结合dify工作流
dify
Q_Q19632884752 天前
python基于Hadoop的超市数据分析系统
开发语言·hadoop·spring boot·python·django·flask·node.js
电商API大数据接口开发Cris2 天前
基于 Flink 的淘宝实时数据管道设计:商品详情流式处理与异构存储
前端·数据挖掘·api
Q_Q5110082852 天前
python的滑雪场雪具租赁服务数据可视化分析系统
spring boot·python·信息可视化·django·flask·node.js·php