We Are Going To Discuss About ImportError : cannot import name ‘ugettext_lazy’. So lets Start this Python Article.
ImportError : cannot import name ‘ugettext_lazy’
- How to solve ImportError : cannot import name 'ugettext_lazy'
Was just about to ask the version but the note (django 4.01) helped. 'ugettext_lazy' seems to be used by the app you are trying to use as well.
'ugettext_lazy' has been deprecated for django 3+ so you won’t be able to use that with a django version >= 3.
https://code.djangoproject.com/ticket/30165 - ImportError : cannot import name 'ugettext_lazy'
Was just about to ask the version but the note (django 4.01) helped. 'ugettext_lazy' seems to be used by the app you are trying to use as well.
'ugettext_lazy' has been deprecated for django 3+ so you won’t be able to use that with a django version >= 3.
https://code.djangoproject.com/ticket/30165
Solution 1
Was just about to ask the version but the note (django 4.01) helped. ‘ugettext_lazy’ seems to be used by the app you are trying to use as well.
‘ugettext_lazy’ has been deprecated for django 3+ so you won’t be able to use that with a django version >= 3.
https://code.djangoproject.com/ticket/30165
Original Author MiTriPy Of This Content
Solution 2
I also got the same issue while using django-hitcount
views.py
from hitcount.views import HitCountDetailView
class PostDetailView(HitCountDetailView):
model = Post
template_name = 'blog/post.html'
slug_field = "slug"
count_hit = True
settings.py
INSTALLED_APPS = [
'hitcount',
.....]
One answer is ugettext_lazy has been removed in Django 4.0 57. Please use gettext_lazy instead
“”
from django.utils.translation import gettext_lazy as _
I put this line of code in the views.py, and got the same error.
Original Author Liang Wei Of This Content
Solution 3
I strongly recommend to downgrade Django from “4.x.x” to “3.x.x” to solve your errors:
pip install django==3.*
Because Django 4.x.x is very new so some packages don’t catch up with Django 4.x.x. So, if you keep using Django 4.x.x, you will get the same or similar errors in the near future then you will spend a lot of time to solve these errors because of Django 4.x.x.
Actually, I got the same or similar errors when using “django-graphql-jwt”, “graphene-django” and so on. Then, for some packages, I could solve such errors but for some packages, I could solve but new other errors occurred then, I couldn’t solve these new other errors.
Finally, I noticed I spent a lot of time to solve such errors because of Django 4.x.x. So again, I strongly recommend to downgrade Django from “4.x.x” to “3.x.x” to solve your errors:
pip install django==3.*
Original Author Kai – Kazuya Ito Of This Content
Solution 4
I have solved the problem by installing the django==3.2 instead of the latest version of Django.
But I`ll still check for the pypi update for the usage in the latest version of Django.
Original Author Liang Wei Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.