[GH-ISSUE #2618] ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' #1658

Closed
opened 2026-02-27 11:18:25 +03:00 by kerem · 6 comments
Owner

Originally created by @kisst on GitHub (Sep 27, 2022).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/2618

Impacted versions

  • OS Type: Debian
  • OS Version: 11
  • Database Type: PostgreSQL
  • Database version: 13.5
  • Modoboa: 2.0.2
  • installer used: Yes
  • Webserver: Nginx

Steps to reproduce

Upgrade the modoboa version to latest ?

Current behavior

Can't run manage.py

modoboa@:~$ /srv/modoboa/env/bin/python3 /srv/modoboa/instance/manage.py
Traceback (most recent call last):
  File "/srv/modoboa/instance/manage.py", line 21, in <module>
    main()
  File "/srv/modoboa/instance/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/srv/modoboa/env/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/srv/modoboa/env/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/srv/modoboa/env/lib/python3.9/site-packages/django/apps/config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/srv/modoboa/env/lib/python3.9/site-packages/modoboa_postfix_autoreply/models.py", line 7, in <module>
    from django.utils.encoding import python_2_unicode_compatible, smart_text
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (/srv/modoboa/env/lib/python3.9/site-packages/django/utils/encoding.py)

Expected behavior

I can run manage.py.

Video/Screenshot link (optional)

Originally created by @kisst on GitHub (Sep 27, 2022). Original GitHub issue: https://github.com/modoboa/modoboa/issues/2618 # Impacted versions * OS Type: Debian * OS Version: 11 * Database Type: PostgreSQL * Database version: 13.5 * Modoboa: 2.0.2 * installer used: Yes * Webserver: Nginx # Steps to reproduce Upgrade the modoboa version to latest ? # Current behavior Can't run manage.py ``` modoboa@:~$ /srv/modoboa/env/bin/python3 /srv/modoboa/instance/manage.py Traceback (most recent call last): File "/srv/modoboa/instance/manage.py", line 21, in <module> main() File "/srv/modoboa/instance/manage.py", line 17, in main execute_from_command_line(sys.argv) File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute django.setup() File "/srv/modoboa/env/lib/python3.9/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/srv/modoboa/env/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/srv/modoboa/env/lib/python3.9/site-packages/django/apps/config.py", line 301, in import_models self.models_module = import_module(models_module_name) File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 790, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/srv/modoboa/env/lib/python3.9/site-packages/modoboa_postfix_autoreply/models.py", line 7, in <module> from django.utils.encoding import python_2_unicode_compatible, smart_text ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (/srv/modoboa/env/lib/python3.9/site-packages/django/utils/encoding.py) ``` # Expected behavior I can run manage.py. # Video/Screenshot link (optional)
kerem closed this issue 2026-02-27 11:18:25 +03:00
Author
Owner

@tonioo commented on GitHub (Sep 30, 2022):

@kisst For same reason, you're not using the latest version of the autoreply plugin.

<!-- gh-comment-id:1263260853 --> @tonioo commented on GitHub (Sep 30, 2022): @kisst For same reason, you're not using the latest version of the autoreply plugin.
Author
Owner

@kisst commented on GitHub (Oct 11, 2022):

Ok that solved this specific error, but still struggling with many others, I had to install back in the day with version 2 in a beta stage, as the "stable" just did not work, but now trying to stabilise it, and it's far from trivial.
I hate to compare it to "others" but ... as I used Mailcow before I seen the power of ./update.sh and it's just light-years ahead.
Some of the current errors are the "usual"

TypeError: '<' not supported between instances of 'memoryview' and 'memoryview'
Which I haven't managed to fix for ages by now, in any of the version I run, and a bunch of
System check identified some issues:
WARNINGS:
I guess it comes down to the discussion we had here maybe it's time to make some progress there.
Anyway this is now "solved" although I think the main modoba pip package should mark the autoreply plugin version as a dependency in setup.py or requirements.txt or where ever this is tracked.

<!-- gh-comment-id:1274869626 --> @kisst commented on GitHub (Oct 11, 2022): Ok that solved this specific error, but still struggling with many others, I had to install back in the day with version 2 in a beta stage, as the "stable" just did not work, but now trying to stabilise it, and it's far from trivial. I hate to compare it to "others" but ... as I used Mailcow before I seen the power of `./update.sh` and it's just light-years ahead. Some of the current errors are the "usual" > TypeError: '<' not supported between instances of 'memoryview' and 'memoryview' Which I haven't managed to fix for ages by now, in any of the version I run, and a bunch of > System check identified some issues: > WARNINGS: I guess it comes down to the discussion we had [here](https://github.com/modoboa/modoboa/discussions/2431) maybe it's time to make some progress there. Anyway this is now "solved" although I think the main modoba pip package should mark the autoreply plugin version as a dependency in setup.py or requirements.txt or where ever this is tracked.
Author
Owner

@antoweb commented on GitHub (Nov 2, 2022):

Hello i have the same error:

(env) root@mail:/srv/modoboa/instance# python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 21, in
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/srv/modoboa/env/lib/python3.8/site-packages/django/core/management/init.py", line 419, in execute_from_command_line
utility.execute()
File "/srv/modoboa/env/lib/python3.8/site-packages/django/core/management/init.py", line 395, in execute
django.setup()
File "/srv/modoboa/env/lib/python3.8/site-packages/django/init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/srv/modoboa/env/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/srv/modoboa/env/lib/python3.8/site-packages/django/apps/config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 848, in exec_module
File "", line 219, in _call_with_frames_removed
File "/srv/modoboa/env/lib/python3.8/site-packages/modoboa_postfix_autoreply/models.py", line 7, in
from django.utils.encoding import python_2_unicode_compatible, smart_text
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (/srv/modoboa/env/lib/python3.8/site-packages/django/utils/encoding.py)

how to solve?

<!-- gh-comment-id:1299881313 --> @antoweb commented on GitHub (Nov 2, 2022): Hello i have the same error: (env) root@mail:/srv/modoboa/instance# python manage.py migrate 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 "/srv/modoboa/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/srv/modoboa/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute django.setup() File "/srv/modoboa/env/lib/python3.8/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/srv/modoboa/env/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/srv/modoboa/env/lib/python3.8/site-packages/django/apps/config.py", line 301, in import_models self.models_module = import_module(models_module_name) File "/usr/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 848, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/srv/modoboa/env/lib/python3.8/site-packages/modoboa_postfix_autoreply/models.py", line 7, in <module> from django.utils.encoding import python_2_unicode_compatible, smart_text ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (/srv/modoboa/env/lib/python3.8/site-packages/django/utils/encoding.py) how to solve?
Author
Owner

@kisst commented on GitHub (Nov 4, 2022):

@antoweb in my case the solution was based on https://modoboa.readthedocs.io/en/latest/upgrade.html#modoboa
I solved it with:

/srv/modoboa/env/bin/python3 -m pip install -U modoboa-postfix-autoreply

<!-- gh-comment-id:1303243680 --> @kisst commented on GitHub (Nov 4, 2022): @antoweb in my case the solution was based on https://modoboa.readthedocs.io/en/latest/upgrade.html#modoboa I solved it with: > /srv/modoboa/env/bin/python3 -m pip install -U modoboa-postfix-autoreply
Author
Owner

@antoweb commented on GitHub (Nov 4, 2022):

Thanks but the problem was all extensions outdated. After updating all extensions the service start successfully

<!-- gh-comment-id:1303456311 --> @antoweb commented on GitHub (Nov 4, 2022): Thanks but the problem was all extensions outdated. After updating all extensions the service start successfully
Author
Owner

@Jammrock commented on GitHub (Jan 27, 2023):

I'm having the same issue. Clean install of modoboa using run.py from modoboa-installer, on a fresh build of Ubuntu 22.04.

<!-- gh-comment-id:1406779783 --> @Jammrock commented on GitHub (Jan 27, 2023): I'm having the same issue. Clean install of modoboa using run.py from modoboa-installer, on a fresh build of Ubuntu 22.04.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#1658
No description provided.