-1

I want to use the emoji library to replace emoji's in text, nothing fancy.

import os
import django
import emoji
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
django.setup()

test = "This is a teststring  test test :-)  "
message_without_emoji = emoji.demojize(test)
print(message_without_emoji)

When I run this code I get an error. I can't figure out why and how to correct this (never used django).

django.core.exceptions.ImproperlyConfigured: Requested setting EMOJI_IMG_TAG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I tried installing django (like suggested), but I still get the error. https://www.youtube.com/watch?v=2FvIa4BADvA

I don't understand why I should install django. In the documentation it isn't mentioned and the examples are straightforward. https://pypi.org/project/emoji/

==> Solution I installed django-emoji and not the emoji library. I'm using PyCharm and in the menu "Show Context Actions" django-emoji was suggested as first in the list.
I did pip uninstall django-emoji and pip install emoji. And now it works fine.

Tralala
  • 233
  • 2
  • 10
  • 1
    `You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings` this says exactly what you have to do. – mx0 Oct 26 '22 at 06:17
  • Does this answer your question? [ImproperlyConfigured: You must either define the environment variable DJANGO\_SETTINGS\_MODULE or call settings.configure() before accessing settings](https://stackoverflow.com/questions/26082128/improperlyconfigured-you-must-either-define-the-environment-variable-django-set) – mx0 Oct 26 '22 at 06:17
  • Solved: pip uninstall django-emoji pip install emoji. – Tralala Oct 26 '22 at 18:56

1 Answers1

1

==> Solution I installed django-emoji and not the emoji library. I'm using PyCharm and in the menu "Show Context Actions" django-emoji was suggested as first in the list. I did pip uninstall django-emoji and pip install emoji. And now it works fine.

Tralala
  • 233
  • 2
  • 10