1

I am trying to use python-social-auth with Django 1.9 and Python 3. As far as I can tell, I have installed all the necessary requirements, and have all the required settings in my settings.py. However, when I try to run migrations, or run the Django dev server, I get the following error:

ImportError: No module named 'openid.association'

The full traceback is as follows:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f6fe7ea5a60>
Traceback (most recent call last):
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/social/apps/django_app/default/models.py", line 9, in <module>
    from social.storage.django_orm import DjangoUserMixin, \
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/social/storage/django_orm.py", line 5, in <module>
    from social.storage.base import UserMixin, AssociationMixin, NonceMixin, \
  File "/home/ethan/.virtualenvs/flywithme/lib/python3.5/site-packages/social/storage/base.py", line 12, in <module>
    from openid.association import Association as OpenIdAssociation
ImportError: No module named 'openid.association'

One suggest I found in my searching was to get rid of python-openid and install python3-openid. This didn't work for me. I have also seen a number of posts related to ImportErrors and python-social-auth, but have not been able to come up with a solution that works for me. I assume that I have misconfigured/failed to configure something, but I am not sure what. What am I doing wrong here?

elethan
  • 16,408
  • 8
  • 64
  • 87

2 Answers2

5

I just had the exact same problem (Python 3.5, Django 1.9.8) and could actually resolve the issue by uninstalling all versions of python-openid and afterwards removing and reinstalling python-social-auth.

Seemingly something went wrong when installing PSA whilst python-openid was still available. So make sure to remove both versions, so python-openid and python3-openid, and then remove PSA as well and try reinstalling it. In the log, you should now see python3-openid getting installed alongside PSA. After doing so I could apply all migrations without a problem.

If that does not work for you resp. does not install python3-openid, you could also try installing PSA from git using pip install git+https://github.com/omab/python-social-auth.git. Apparently that helped a person who ran into a similar issue a year ago (https://github.com/omab/python-social-auth/issues/588).

Hope it helps!

Kim
  • 1,361
  • 3
  • 18
  • 24
  • Thank you for the answer. I ended up "solving" this probelm by using django-allauth instead: http://www.intenct.nl/projects/django-allauth/. I am liking this library a lot so far. – elethan Aug 03 '16 at 15:13
  • Or just: `pip install --ignore-installed python-social-auth`. – Palasaty Dec 08 '17 at 14:47
3

This happened for when I was trying to setup social-auth-app-django, I'm guessing it will be same for other similar packages.

To solve this issue, Remove both the python openid versions.

pip uninstall python-openid
pip uninstall python3-openid

Then uninstall social-auth-app-django or similar app

pip uninstall social-auth-app-django

Now install your package again. It should download back the proper dependency. If it doesn't you can always reinstall using pip install python3-openid

Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34