0

I tried to start my Celery worker like this celery -A backend worker -l info but I got this error

ModuleNotFoundError: No module named 'rest_framework'

I'm using Poetry and I already have my virtual environment activated and it was included in my pyproject.toml

python = "^3.9"
aiohttp = "^3.7.4"
six = "^1.16.0"
Django = "^3.2.5"
djangorestframework = "^3.12.4"
python-dotenv = "^0.19.0"
psycopg2 = "^2.9.1"
celery = "^5.1.2"
redis = "^3.5.3"

So then I ran pip install djangorestframework and the error went away but I got a new error

ModuleNotFoundError: No module named 'psycopg2'

Which I also solved with pip install psycopg2, but it doesn't make sense why I have to do this for Celery to work? Before I could start my Django backend without this so I know my dependencies are there and from pyproject.toml as well

A.K.M. Adib
  • 517
  • 1
  • 7
  • 22
  • 2
    Are you calling `celery -A backend worker -l info` from within your poetry environment? i.e. `poetry run celery -A backend worker -l info` or `poetry shell` to activate the virtual environment first? – PeptideWitch Aug 18 '21 at 04:20
  • `poetry shell` to activate the virtual environment first – A.K.M. Adib Aug 18 '21 at 15:04
  • The former seems to work, but why? – A.K.M. Adib Aug 18 '21 at 15:05
  • 1
    I'm not certain, but depending on what program or terminal you're using to drive `poetry shell` it may not actually be activating the environment properly. See https://github.com/python-poetry/poetry/issues/571 – PeptideWitch Aug 19 '21 at 00:23

0 Answers0