Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'python_2_unicode_compatible' when running migrations for Django-Invitations

First, I might want to mention I'm a beginner with Django. I'm trying to install Django-Invitations on my app to send sign up invitations. I followed their README instructions.

pip install django-invitations

# Add to settings.py, INSTALLED_APPS
'invitations',

# Append to urls.py
url(r'^invitations/', include('invitations.urls', namespace='invitations')),

# Run migrations
python manage.py migrate

I also pip installed all the requirements from their requirements file:

coverage==4.5.4 flake8==3.7.9 freezegun==0.3.12 mock==3.0.5 pytest==5.2.2 pytest-django==3.6.0 pytest-cov==2.8.1 tox==3.14.0

But I keep getting the same error when I run migrations for the first time:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    django.setup()
  File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\apps\config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Users\maxim\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\invitations\models.py", line 12, in <module>
    from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible'

Any idea what the issue might be?

like image 471
Max Vallee Avatar asked Mar 13 '26 22:03

Max Vallee


1 Answers

It should work if you install six.

All you then need to do is replace django.utils.encoding with six in your models.py.

like image 123
MGL Avatar answered Mar 15 '26 15:03

MGL