celery - python celery: ImportError: cannot import name from 'celery_worker' (/home/simha/app/src/celery_worker.py)
问题描述
我有以下文件夹
app
|--venv
|--src
|--celery_worker.py
|--test.py
celery_worker.py
from celery import Celery
celery = Celery("tasks", broker="redis://redis:6379/0")
@celery.task(name="test")
def test():
print("test print")
def test2():
print("test2 print")
test.py
def hare():
print("testing")
现在在src
文件夹中我打开了一个 python shell 并检查
>>> from test import hare
>>> hare()
testing
然而
>>> from celery_worker import test
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'test' from 'celery_worker' (/home/simha/app/src/celery_worker.py)
并且
>>> from celery_worker import test2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'test2' from 'celery_worker' (/home/simha/app/src/celery_worker.py)
解决方案
推荐阅读
- gsap - 使用 ScrollMagic 反转动画
- fedora - vncserver:几何 800x600 深度在 Fedora 上无效
- java - 如何关闭并行流中使用的线程本地自动关闭?
- angular - entryComponents错误中的多个对话框组件
- makefile - 如何在 OpenWRT 中使用单个 Makefile 编译多个 C 文件?
- database - 将两个表的查询与另一个表连接起来
- android - 如何让导航视图上方的状态栏颜色在打开时发生变化
- c++ - 将单一 BGR 颜色转换为 HSV C++ OpenCV 4
- node.js - 如何将 Node-js 数据库查询绑定到 Web 表单
- ruby-on-rails - 猴子用 Rails 用业务逻辑修补核心类