0

I'm trying to add django-messages to my app but I'm getting this error when I add it to my installed apps

ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\encoding.py)

I've looked up this error and apparently it's caused by this line in Django-Messages models.py

from django.utils.encoding import python_2_unicode_compatible

To fix it I should change it to

from django.utils.six import python_2_unicode_compatible

As this is a third party app, how should I change this line?

Should I copy the file structure into my own project (creating a django-messages folder among my apps then a models.py file inside it) and copy/paste the entire models.py into there and then change the line? This seems wrong, but I don't know how else to fix it.

Or does the fact that it's using an outdated import signify that the app isn't maintained and therefore shouldn't be used at all?

Thank you.

MeL
  • 1,269
  • 3
  • 12
  • 30
horse
  • 479
  • 7
  • 25

1 Answers1

1

I can suggest two options. First, you can clone it on GitHub (i.e. download all the files) and then paste this into your project folder (along with your other apps). And then you can make any changes you wish. Of course it remains to be seen whether it will work then, as there might be other issues. It seems to be compatible with Django 1.11 - 2.2. But I would think that it's a better option than doing this all yourself. Unless you can find a different app that suits your needs.

Second, assuming you are using a virtual environment, you can navigate to where all your packages are installed. I'm not sure where this will be located for you, but it should be something like envs\<name of env>\Lib\site-packages. And there you can make any changes you wish - just search for the relevant file.

Hope this helps.

MeL
  • 1,269
  • 3
  • 12
  • 30
  • Thank you. I like your first suggestion of cloning the entire app into my projects folder as this would give me complete control, however is this good practice? I was under the impression that doing such things is discouraged because bug fixes / security updates that the creators make to the app wouldn't be implemented into my version of the app? Thank you. – horse Jun 30 '20 at 03:26
  • Well yes, I guess that depends if the app is maintained or not? If it's not being maintained anymore, then there won't be any bug fixes... But I guess therefore the second option would be better. – MeL Jun 30 '20 at 03:27