Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 954
pedro.caicedo.dev Avatar asked Oct 03 '20 02:10

pedro.caicedo.dev


3 Answers

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.

like image 157
DejanLekic Avatar answered Oct 19 '22 08:10

DejanLekic


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.

like image 39
camtech Avatar answered Oct 19 '22 10:10

camtech


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.

like image 2
Poonam Adhav Avatar answered Oct 19 '22 09:10

Poonam Adhav