ImportError: cannot import name 'Command' from 'celery.bin.base'
Asked Answered
A

5

21

When I run the command

flower -A main --port=5555

Flower doesn't work, the error is:

> ImportError: cannot import name 'Command' from 'celery.bin.base'

Any ideas? Main is a Django Project

Alphabetical answered 3/10, 2020 at 2:1 Comment(3)
Try installing python3-celery. sudo apt install python3-celery also pip3 install celeryActon
Yes, it doesn't workAlphabetical
Is a reported bug github.com/mher/flower/issues/1029 , the temporal solution is dowgraded celery to 4.4.7 as packetflow, thanks @PaxAlphabetical
B
28

Flower is always lagging behind Celery, so if you use the latest Celery (they refactored the CLI) it will probably fail. Stick to 4.4.x until Flower catches up.

Brita answered 3/10, 2020 at 13:29 Comment(1)
Here's the GitHub issue to track progress: github.com/mher/flower/issues/1029Peroration
S
17

One workaround, if you prefer to avoid downgrading your Celery worker, is to run a previous version of Flower separate from your main Celery install. For example, in a container or separate venv. Flower just monitors your broker, and can be run completely separate from your Celery worker.

Flower in Docker example

For your Django/Celery install, run Celery normally (no Flower):

celery -A main worker

For Flower, use docker image mher/flower:0.9.5, which internally uses Celery 4.4.6, and is reported working.

Here is a sample docker run command:

docker run --name flower -p 5555:5555 mher/flower:0.9.5 flower --broker=redis://redis-address

Note: You must change the broker address to be your broker's dns-resolvable name or ip. For rabbitmq, use --broker=amqp://guest@rabbitmq-address:5672//. See the url documentation for advanced options.

Once running, Flower should be available at the Docker host's IP:5555

You can alternatively create a docker-compose file encapsulating all of the arguments in the run command, and use docker-compose up -d.

Alternatives

If preferred, you can also do all this without Docker, using pip install flower redis celery==4.4.7, as long as it is separate from your main Celery install, and then run flower with flower --broker=redis://redis-address. A separate venv may work for this.

See the github issue for future updates on the original bug.

Shapiro answered 14/10, 2020 at 5:47 Comment(0)
V
2

Had same issue while working on celery 5.0.5 so switched to celery 4.4.7 version with flower 0.9.7 and it worked.

Vendor answered 8/4, 2021 at 18:57 Comment(0)
K
0

You may downgrade Celery as many people have already suggested, or, as in my case, upgrade flower to the last version, which is now 1.0.0 since july 2021 -> https://pypi.org/project/flower/.

I can confirm this last version is compatible with celery[auth,redis,tblib]==5.1.2.

Personally I'd suggest that you tried to upgrade packages instead of downgrading them, and that upgrading flower has less chances of breaking your project than downgrading celery.

Kozlowski answered 2/3, 2022 at 21:52 Comment(0)
G
0

Maybe you can try pip install https://github.com/mher/flower/zipball/master#egg=flower

Grinnell answered 8/3, 2022 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.