Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'smart_text' from 'django.utils.encoding' #381

Open
MSoup opened this issue Jan 12, 2022 · 2 comments
Open

cannot import name 'smart_text' from 'django.utils.encoding' #381

MSoup opened this issue Jan 12, 2022 · 2 comments

Comments

@MSoup
Copy link

MSoup commented Jan 12, 2022

My setup is Django 4.0, Python 3.8.10
I came across this issue while working with django-jenkins:

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 "C:\git\django-mssql\venv\lib\site-packages\django\core\management\__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "C:\git\django-mssql\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\git\django-mssql\venv\lib\site-packages\django\core\management\__init__.py", line 263, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "C:\git\django-mssql\venv\lib\site-packages\django\core\management\__init__.py", line 39, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Users\AppData\Local\Programs\Python\Python38\lib\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 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\git\django-mssql\venv\lib\site-packages\django_jenkins\management\commands\jenkins.py", line 10, in <module>
    from django_jenkins.runner import CITestSuiteRunner
  File "C:\git\django-mssql\venv\lib\site-packages\django_jenkins\runner.py", line 9, in <module>
    from django.utils.encoding import smart_text
ImportError: cannot import name 'smart_text' from 'django.utils.encoding' (C:\git\django-mssql\venv\lib\site-packages\django\utils\encoding.py)

Upon doing some digging, it turns out that from django.utils.encoding has been rewritten a little. The only methods with "smart" in them are smart_str and smart_bytes. Thus, the solution is to change all occurences of smart_text to smart_str in runner.py

I just wanted to share this here in case anyone else came across this problem.

@WillWagnerIV
Copy link

Thanks to MSoup's suggestion I was able to solve this using the same fix in a standard Django setup in a venv.

I changed one instance of smart_text to smart_str in the file:

venv/lib/python3.9/site-packages/django_bootstrap_breadcrumbs/templatetags/django_bootstrap_breadcrumbs.py

Everything works again! Thanks!

@Lord-baba99
Copy link

Thanks, that work!!!!👍🏾👍🏾👍🏾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants