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

使用pylint时无法导入'celery'但Django运行正常的问题求助

使用pylint时无法导入'celery'但Django运行正常的问题求助

我正在做一个Django项目,用uv作为包管理器,依赖都通过pyproject.toml管理,以下是我的配置相关部分:

pyproject.toml(相关片段)

[project]
name = "port-backend"
version = "0.1.0"
description = "Backend service for port.az"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "celery>=5.4.0",
    "django==4.2",
    "djangorestframework>=3.15.2",
    "djangorestframework-simplejwt>=5.5.0",
    "drf-spectacular>=0.28.0",
]

[dependency-groups]
dev = [
    "pylint>=2.0.0",
]

[tool.pylint.MASTER]
ignore-paths = ['.venv/']
disable = [
    'C0415',  # Import outside toplevel
    'E0401',  # Import error
]

已执行的步骤

  1. 我运行了uv sync,创建了新的.venv虚拟环境并安装了所有依赖。
  2. VS Code检测到了这个新环境,我选择使用它,并且确认虚拟环境已经激活。
  3. 运行uv run manage.py runserver完全正常,说明Django和Celery都安装正确。
  4. 但是运行uv run pylint .时出现了以下错误:
************* Module manage
manage.py:12:8: C0415: Import outside toplevel (django.core.management.execute_from_command_line) (import-outside-toplevel)
************* Module config.celery_app
config/celery_app.py:3:0: E0401: Unable to import 'celery' (import-error)

我已经尝试过的方法

  • 用uv pip list确认了Celery已经安装在.venv里,列表里确实有celery。
  • 确认VS Code的终端里.venv已经激活(终端显示(port-backend) ➜ port_backend))。
  • 尝试运行uv run python -c "import celery",这个命令完全没有报错。

我的问题

为什么pylint找不到Celery(报E0401: Unable to import 'celery'错误),但Django和Celery在manage.py里运行完全正常?我该怎么让pylint正确识别已安装的依赖?

备注:内容来源于stack exchange,提问作者Zaman Kazimov

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.13 20:03:08