omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

ImportError: No module named social_django.models #1073

Closed palzuncoff closed 7 years ago

palzuncoff commented 7 years ago

When i tried makemigrations i take following error

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
    django.setup()
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/social/apps/django_app/default/models.py", line 1, in <module>
    from social_django.models import AbstractUserSocialAuth, UserSocialAuth, Nonce, Association, Code, DjangoStorage
ImportError: No module named social_django.models
ghoshbishakh commented 7 years ago

You also need to install social-auth-app-django and add social.apps.django_app.default to your INSTALLED_APPS in your settings.py file.

palzuncoff commented 7 years ago

error changed

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/social/apps/django_app/default/models.py", line 1, in <module>
    from social_django.models import AbstractUserSocialAuth, UserSocialAuth, Nonce, Association, Code, DjangoStorage
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/social_django/models.py", line 68, in <module>
    class UserSocialAuth(AbstractUserSocialAuth):
  File "/home/giverroot/django/gve1/lib/python2.7/site-packages/django/db/models/base.py", line 113, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class social_django.models.UserSocialAuth doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
ghoshbishakh commented 7 years ago

@palzuncoff

As for Dec 03 2016, this library is now deprecated.

You should be using the new social-app-django.

Check out how to use that in this doc: https://github.com/omab/python-social-auth/blob/master/MIGRATING_TO_SOCIAL.md

palzuncoff commented 7 years ago

Thank you

omab commented 7 years ago

Somebody on #550 experienced the same troubles.

wuhaotju commented 7 years ago

hi,how did you sloved it? the second fault.

wuhaotju commented 7 years ago

ok, i know how to fix it,thx.and by the way.i have spell the wrong word 'solves',ha ha

fendyh commented 7 years ago

I'm now encountering an error, it says ImportError at / cannot import name engines it traced back to /lib/python2.7/site-packages/social_django/strategy.py in this line from django.template import TemplateDoesNotExist, RequestContext, loader, engines

omab commented 7 years ago

@fendyh what's your django version? Is django installed in your env (virtual or not)? What happens if you run from django.template import engines in a python shell within it?

fendyh commented 7 years ago

@omab My Django version is 1.7.3 , and yes from django.template import engines generates error as it does not exist, what Django version should I use ? And yes My Django is installed in virtualenv

Thank you for the answer!

fendyh commented 7 years ago

@omab I've tried upgrading my Django to the newest version and it generates so much errors, I think changing my Django version is not an option

omab commented 7 years ago

@fendyh, PSA is dropping support for Django <= 1.7, I do recommend updating at least to 1.8, or stick with PSA version 0.2.21

haloween commented 7 years ago

Ok. You need to have your INSTALLED_APPS like: 'social_django', 'social.apps.django_app.default',

fendyh commented 7 years ago

Thanks for the answers. I finally managed to implement it by installing Django Social Auth instead, as it still has support for Django 1.7.

omab commented 7 years ago

@fendyh I do not recomment going back to django-social-out, that codebase was abandoned years ago and it's very outdated at the memoment. If you stick to python-social-auth==0.2.21, you will have Django 1.7 support.

fendyh commented 7 years ago

Thanks for the answer ! I followed your suggestion and try installing python-social-auth==0.2.21 instead. As I have already implemented django-social-auth==0.7.28, I will need to migrate it to python-social-auth, and so I followed the instructions laid in http://psa.matiasaguirre.net/docs/configuration/porting_from_dsa.html, as it turns out, when I run manage.py runserver, there's a warning You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. and so I run manage.py migrate, and here's the result Running migrations: Applying social_auth.0001_initial...Traceback (most recent call last): File "./manage.py", line 10, in <module> ... django.db.utils.ProgrammingError: relation "social_auth_association" already exists

can you help with this ? this maybe a newbie error, sorry but I'm new to Django, I don't know how to solve this, but thanks for helping !

omab commented 7 years ago

Try with python manage.py migrate --fake.

fendyh commented 7 years ago

@omab Thanks for the answer ! the fake migration worked, and I can login and logout normally again. there's still an issue though, when I go to http://localhost:8000/admin/social_auth/usersocialauth/ , it generates an error `AttributeError at /admin/social_auth/usersocialauth/

'Options' object has no attribute 'get_fields'`

further stacktrace, the error generated originated from /titanium_toys_env/lib/python2.7/site-packages/social/apps/django_app/default/admin.py in get_search_fields, particularly this line: `

        )

        if search_fields is None:

            _User = UserSocialAuth.user_model()

            username = getattr(_User, 'USERNAME_FIELD', None) or \

                       hasattr(_User, 'username') and 'username' or \

                       None

            fieldnames = ('first_name', 'last_name', 'email', username)

            all_names = self._get_all_field_names(_User._meta) // this line generates the error

 ...

            search_fields = [name for name in fieldnames

                                if name and name in all_names]

        return ['user__' + name for name in search_fields]

    @staticmethod

    def _get_all_field_names(model):

`

thanks !!

jpic commented 7 years ago

I've fixed this in my project by doing the above mentioned steps and changing social_auth to social_django in my own migrations. There's probably a better way though

tytarenko commented 7 years ago

Could you please tell me, why I have install this packаge "social-auth-app-django" and why it does not work without it. Nothing is said in the docs about it. And I have rollback to version 0.2.21 because current version on pip does not work. It not return authorized user

omab commented 7 years ago

@tytarenko you don't, you can stick with 0.2.21 or migrate to the new version that depends on the new packages, the library is now split in smaller modules, and anything >=0.3.0 will depend on the new packages.

apache10 commented 7 years ago

Traceback (most recent call last): File "manage.py", line 22, in execute_from_command_line(sys.argv) File "/home/gaurav/.local/lib/python2.7/site-packages/django/core/management/init.py", line 367, in execute_from_command_line utility.execute() File "/home/gaurav/.local/lib/python2.7/site-packages/django/core/management/init.py", line 341, in execute django.setup() File "/home/gaurav/.local/lib/python2.7/site-packages/django/init.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/home/gaurav/.local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models(all_models) File "/home/gaurav/.local/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models self.models_module = import_module(models_module_name) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/default/models.py", line 1, in from social_django.models import AbstractUserSocialAuth, UserSocialAuth, Nonce, Association, Code, DjangoStorage ImportError: No module named social_django.models

I have installed social-auth-app-django and added social.apps.django_app.default to INSTALLED_APPS in settings.py file.

gitCommitLit commented 6 years ago

please can someone help. I am getting this:

Unhandled exception in thread started by <function check_errors..wrapper at 0x1053a3f28> Traceback (most recent call last): File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper fn(*args, kwargs) File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run self.check(display_num_errors=True) File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/core/management/base.py", line 385, in check include_deployment_checks=include_deployment_checks, File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/core/management/base.py", line 372, in _run_checks return checks.run_checks(kwargs) File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks new_errors = check(app_configs=app_configs) File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/core/checks/urls.py", line 14, in check_url_config return check_resolver(resolver) File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/core/checks/urls.py", line 24, in check_resolver for pattern in resolver.url_patterns: File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/utils/functional.py", line 35, in get res = instance.dict[self.name] = self.func(instance) File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/urls/resolvers.py", line 310, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/utils/functional.py", line 35, in get res = instance.dict[self.name] = self.func(instance) File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/urls/resolvers.py", line 303, in urlconf_module return import_module(self.urlconf_name) File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/Users/theappmaker/jasmyndelivery/jasmyndelivery/urls.py", line 24, in url(r'^api/social/', include('rest_framework_social_oauth2.urls')), File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/django/conf/urls/init.py", line 50, in include urlconf_module = import_module(urlconf_module) File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/rest_framework_social_oauth2/urls.py", line 6, in from .views import ConvertTokenView, invalidate_sessions File "/Users/theappmaker/deliveryenv/jasmyndeliveryenv/lib/python3.6/site-packages/rest_framework_social_oauth2/views.py", line 5, in from oauth2_provider.ext.rest_framework import OAuth2Authentication ModuleNotFoundError: No module named 'oauth2_provider.ext'

omab commented 6 years ago

@Balance-Sun, that's not related to this project, please refer to the corresponding project.