Installing Celery with Django - django

I'm trying to install celery with django and I'm get the following error:
from celery.task import sets
ImportError: cannot import name sets
How can I fix that?

Installing a newer version of celery might work. Or your install might not be complete.
But sets should be a part of celery.task.
Atleast, the latest docs indicate that this should be the case: http://ask.github.com/celery/reference/celery.task.sets.html

https://github.com/ask/celery/issues#issue/315
looks like an issue that has been reported.
You might be interested in these 2 pages of the #celery irc log
http://botland.oebfare.com/logger/celery/2011/3/4/2/
http://botland.oebfare.com/logger/celery/2011/3/4/3/

Related

Facing an Error while trying to Import ModelStep

I am trying to import ModelStep using the code
from sagemaker.workflow.model_step import ModelStep
But it is throwing the error
ModuleNotFoundError: No module named 'sagemaker.workflow.model_step'
How can I resolve this issue?
This feature, in sagemaker-python-sdk, was introduced starting with release 2.90.0 (16 May 2022).
I suggest always keeping sagemaker updated, they come out with updates very frequently and quite important:
pip install -U sagemaker

Set up django-celery-email for local dev

It seems the best way to send emails from the django-allauth app asynchronously is to simply install django-celery-email. But the packages warns that
This version requires the following versions:Python 2.7 and Python3.5, Django 1.11, 2.1, and 2.2 Celery 4.0
I've only been using python for several months and never encountered a situation where two python version are needed on a project. And I'm using the official recommendation of pipenv for local development. A quick google shows that it isn't possible to have two python interpreters installed in the virtual environment. Since the plugin seems so popular I wondered how others were setting it up? Apologies if I've missed something major that explains this.
A bonus answer would also take into account that I am using docker and the docker image will install the python packages like this.
RUN pipenv install --system --deploy --ignore-pipfile
Many thanks in advance.
I am pretty sure it is just inaccurate description in the project docs, so you need either python 2.7 or python >=3.5 to be installed
In the end I didn't use django-celery-email. It's easy to send the emails generated by the django-allauth app without this package.
I used these resources -
https://github.com/anymail/django-anymail/issues/79
https://docs.djangoproject.com/en/2.2/topics/email/#defining-a-custom-email-backend
Basically you do this to get it working.
In settings.py define a CustomEmailBackend -
EMAIL_BACKEND = "users.backends.CustomEmailBackend"
In a backend.py file define the backend -
from django.core.mail.backends.base import BaseEmailBackend
from .tasks import async_send_messages
class CustomEmailBackend(BaseEmailBackend):
def send_messages(self, email_messages):
async_send_messages.delay(email_messages)
return len(email_messages)
And this is the task -
from django.core.mail import get_connection
from abstract_base_user.celery import app
#app.task(rety_backoff=True, serializer="pickle")
def async_send_messages(email_messages):
conn = get_connection(backend='anymail.backends.mailgun.EmailBackend')
conn.send_messages(email_messages)
The celery django app should be set up in the standard way as defined at https://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
And the celery settings in the settings.py need include the pickle content type -
CELERY_ACCEPT_CONTENT = ['json', 'pickle']
Obviously you need to include your anytime settings and broker settings too. But this should be enough to get anybody started.

Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'

It's the first time I work with django rest and Django Oauth toolkit
I'm following this tutorial
oauth2-with-django-rest-framework
But when I run python manage.py migrate I get the following error:
ImportError: Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named ext.rest_framework.
What is going wrong ? is there another module I should install ?
my virtual environment contains :
certifi==2017.4.17
chardet==3.0.4
Django==1.11.2
django-extensions==1.8.1
django-oauth-toolkit==1.0.0
djangorestframework==3.6.3
idna==2.5
oauthlib==2.0.2
pytz==2017.2
requests==2.18.1
six==1.10.0
Unidecode==0.4.21
urllib3==1.21.1
It looks like oath2_provider.ext has been moved to oauth_provider.contrib. You could try installing an older version of django-oauth-toolkit, or try changing the value in DEFAULT_AUTHENTICATION_CLASSES from:
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
to:
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
Note that the tutorial is a couple of years old, you might find other problems like this.
I was facing same issue. In my setting file DEFAULT_AUTHENTICATION_CLASSES was already
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
I just installed older version as #Alasdair ask. My issue resolved. thanks

ImportError: No module named comments django

I'm using os x , I tried to run the project that I installed from Github
https://github.com/cfpb/idea-box
but there is error says : ImportError: No module named comments
maybe I miss something but since I'm newbie in Django I can't figure it out
Django comments are deprecated in latest version. You can either install older django version (such as 1.5).
Or the better solution is to install comments from external repository like so:
pip install django-contrib-comments
and then change all imports like this:
from django.contrib.comments.models import Comment # old
from django_comments.models import Comment # new
Sources:
Django's docs
Another question

why I am Getting Import error for eve.io.SQLAlchemy?

I am running the demo script available at
https://gist.github.com/Tefnet/5430309
I am getting following error, despite having all libraries
flask sqlalchemy validate SQL
File demo.py in line 2 , in <module>
from eve.io.sqlalchemy import SQLAlchemy, Validator
ImportError no module named sqlalchemy
Not sure why is it giving ? even though I have installed EVE, SQLAlchemy, flask
The SQLAlchemy branch is a work in progress. It has evolved quite a bit from the fork linked by codegeek and now is almost on par (feature-wise) with v0.4dev.
Eve-SQLAlchemy branch
So if you want to play around with it, make sure to pull that branch. Also, one thing it's not been done yet is update requirements.txt and setup.py, so you will want to pip install sqlalchemy on your own.
You can find a rather complete Eve-SQL log by checking out this very long lived ticket.
There is no eve.io.sqlalchemy by looking at the official source code of eve. The Gist that you are looking at is a fork from eve but the changes are not pulled in yet officially.
See the commit changes here.