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

已安装flags包仍报ModuleNotFoundError的问题排查与解决

问题描述

已成功安装flags包:

pip install flags                                                                                                                                                                                                       ─╯
Collecting flags
  Downloading flags-0.0.1.2.tar.gz (1.0 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: flags
  Building wheel for flags (pyproject.toml) ... done
  Created wheel for flags: filename=flags-0.0.1.2-py3-none-any.whl size=1698 sha256=9f7a6085b3e27960f9a56d8a3e2cb4781e1f6369fd572ab5610df42e745559ae
  Stored in directory: /Users/l028/Library/Caches/pip/wheels/1a/fc/32/fdc14bda566c3b37624cad853634811349fe105b21a829e7e5
Successfully built flags
Installing collected packages: flags
Successfully installed flags-0.0.1.2

但运行依赖flags的llmstack时,出现以下错误:

llmstack                                                                                                                                                                                                                ─╯
/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/pydub/utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
  warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/llmstack/apps/apps.py:47: RuntimeWarning: coroutine 'SyncToAsync.__call__' was never awaited
  sync_to_async(add_missing_app_types)()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.
  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
Traceback (most recent call last):
  File "/Users/l028/.pyenv/versions/llm_stack/bin/llmstack", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/llmstack/cli.py", line 308, in main
    run_django_command(["manage.py", "migrate", "--noinput"])
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/llmstack/cli.py", line 18, in run_django_command
    execute_from_command_line(command)
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/management/commands/migrate.py", line 100, in handle
    self.check(databases=[database])
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/management/base.py", line 486, in check
    all_issues = checks.run_checks(
                 ^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    return check_method()
           ^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/urls/resolvers.py", line 519, in check
    for pattern in self.url_patterns:
                   ^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/urls/resolvers.py", line 738, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
                       ^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/urls/resolvers.py", line 731, in urlconf_module
    return import_module(self.urlconf_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/llmstack/server/urls.py", line 7, in <module>
    path("", include("llmstack.apps.urls")),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/django/urls/conf.py", line 39, in include
    urlconf_module = import_module(urlconf_module)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/l028/.pyenv/versions/3.11.8/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/llmstack/apps/urls.py", line 3, in <module>
    from . import apis
  File "/Users/l028/.pyenv/versions/3.11.8/envs/llm_stack/lib/python3.11/site-packages/llmstack/apps/apis.py", line 15, in <module>
    from flags.state import flag_enabled
ModuleNotFoundError: No module named 'flags.state'; 'flags' is not a package
原因分析

你安装的flags包(版本0.0.1.2)是一个无关的空包,并非llmstack依赖的django-flags。llmstack需要的flags.state模块属于django-flags这个Django扩展包,而你装的flags包没有任何实际模块内容,导致Python无法找到flags.state。

解决步骤
  • 卸载错误的flags包:
    pip uninstall -y flags
    
  • 安装正确的django-flags包:
    pip install django-flags
    
  • 确保llmstack的Django配置文件中,INSTALLED_APPS列表包含'flags'(django-flags需要注册为Django应用才能正常使用)
  • 重新运行llmstack:
    llmstack
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 19:30:54