0

I have deployed my project to Heroku. But I got "Internal server error"

"ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (/app/.heroku/python/lib/python3.8/site-packages/django/utils/translation/init.py)"

Yes, I know that I should write "gettext_lazy" instead. But I can't find this file in my project. Can I edit code in Heroku container? How? I got this error only after deploy. I don't understand where this file is situated. Help me, please.

Traceback (most recent call last):


    File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/base.py", line 373, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/base.py", line 417, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/base.py", line 90, in wrapped
    res = handle_func(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 75, in handle
    self.check(databases=[database])
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/management/base.py", line 438, in check
    all_issues = checks.run_checks(
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/checks/registry.py", line 77, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 446, in check
    for pattern in self.url_patterns:
  File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 632, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/resolvers.py", line 625, in urlconf_module
    return import_module(self.urlconf_name)
  File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/Bianka/urls.py", line 28, in <module>
    path('', include('bianka_site.urls')),
  File "/app/.heroku/python/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/bianka_site/urls.py", line 2, in <module>
    from . import views
  File "/app/bianka_site/views.py", line 8, in <module>
    from .forms import CommentForm, LikeForm
  File "/app/bianka_site/forms.py", line 3, in <module>
    from snowpenguin.django.recaptcha3.fields import ReCaptchaField
  File "/app/.heroku/python/lib/python3.8/site-packages/snowpenguin/django/recaptcha3/fields.py", line 7, in <module>
    from django.utils.translation import ugettext_lazy as _
ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (/app/.heroku/python/lib/python3.8/site-packages/django/utils/translation/__init__.py)

my requirements.txt

asgiref==3.4.1
backports.zoneinfo==0.2.1
certifi==2021.10.8
charset-normalizer==2.0.10
dj-database-url==0.5.0
Django==4.0
django-ckeditor==6.2.0
django-js-asset==1.2.2
django-modeltranslation==0.17.3
django-recaptcha3==0.4.0
fontawesomefree==6.0.0
gunicorn==20.1.0
idna==3.3
Pillow==8.4.0
psycopg2==2.9.3
requests==2.27.1
six==1.16.0
sqlparse==0.4.2
tzdata==2021.5
urllib3==1.26.7
whitenoise==6.0.0
  • See the linked duplicate. This is likely a Django version mismatch. Make sure to specify the right version constraints in your `requirements.txt`. This is a [fairly old change](https://code.djangoproject.com/ticket/30165), though—if it's an option, I suggest you update your local version instead of using quite an old, [unsupported](https://www.djangoproject.com/download/#supported-versions), version of Django. – ChrisGPT was on strike Apr 26 '22 at 14:18
  • Thank you. What do you mean 'linked duplicate'? I have 'Django==4.0' in requirements.txt – Vladyslav Chumak Apr 26 '22 at 14:26
  • I mean the link in the blue box at the top of your question that says "This question already has answers here". Are you also using Django==4.0 locally? I suspect not, if this code works locally. – ChrisGPT was on strike Apr 26 '22 at 14:39
  • Sure. I know that my question is the same. But I don't have such problem locally. I used pip freeze > requirements.txt And got this only on external server. And I can't find specified file (init.py) in my project. OK I will check versions, anyhow – Vladyslav Chumak Apr 26 '22 at 14:56
  • That file isn't "in" your project, it's in one of your dependencies. Modifying code in dependencies is almost always a bad idea. Have you upgraded Django? Are you _entirely sure_ you're using version 4 locally? Activate your environment, then from a Python shell run `import django` and then `django.__version__`. – ChrisGPT was on strike Apr 26 '22 at 15:04
  • Please [edit] your question and show the entire traceback, not just the `ImportError` bit. – ChrisGPT was on strike Apr 26 '22 at 15:05
  • I use django 4.0.4 version. Maybe the problem is in runtime.txt There is "python-3.8.13" but locally I use 3.9.9 version – Vladyslav Chumak Apr 26 '22 at 16:00
  • It's unlikely that your `runtime.txt` is relevant here (though I have no idea why you'd chose to use Python 3.8 on Heroku if you're using 3.9 locally), but it looks like [one of your dependencies is](https://github.com/kbytesys/django-recaptcha3). Please [edit] your `requirements.txt` into your question. – ChrisGPT was on strike Apr 26 '22 at 17:49
  • I think I know how to check it. Now I remember that after installing recaptcha3 I had to change that "ugettext". And now during deploying proceed the same installation on the new server with the same issue. Thank you for explanation. – Vladyslav Chumak Apr 27 '22 at 07:03
  • This is a fantastic example of why you shouldn't modify library code. Locally, you are no longer using the version of that library defined in your `requirements.txt`. You're using a slightly different version that isn't available upstream. – ChrisGPT was on strike Apr 27 '22 at 10:53

0 Answers0