使用Django的python-social-auth:ImportError:没有名为'openid.association'的模块

时间:2016-06-28 14:01:08

标签: python django python-3.x python-social-auth python-openid

我正在尝试将python-social-auth与Django 1.9和Python 3一起使用。据我所知,我已经安装了所有必要的要求,并在我的settings.py中拥有所有必需的设置。但是,当我尝试运行迁移或运行Django dev服务器时,我收到以下错误:

ImportError: No module named 'openid.association'

完整的追溯如下:

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'

我在搜索中发现的一个建议是删除python-openid并安装python3-openid。这不适合我。我还看到了许多与ImportErrorpython-social-auth相关的帖子,但未能找到适合我的解决方案。我假设我配置错误/未能配置,但我不确定是什么。我在这里做错了什么?

2 个答案:

答案 0 :(得分:5)

我刚才遇到了完全相同的问题(Python 3.5,Django 1.9.8),并且实际上可以通过卸载所有版本的python-openid然后删除并重新安装来解决此问题 python-social-auth。

安装PSA时似乎出现了问题,而python-openid仍然可用。因此,请确保删除两个版本,以便python-openid和python3-openid,然后删除PSA并尝试重新安装。在日志中,您现在应该看到python3-openid与PSA一起安装。在这样做之后,我可以毫无问题地应用所有迁移。

如果那对你不起作用的话。不安装python3-openid,你也可以尝试使用pip install git+https://github.com/omab/python-social-auth.git从git安装PSA。显然,这帮助了一年前遇到类似问题的人(https://github.com/omab/python-social-auth/issues/588)。

希望它有所帮助!

答案 1 :(得分:1)

发生这种情况的原因是,当我尝试设置social-auth-app-django时,我猜对于其他类似的软件包也是如此。

要解决此问题,请同时删除两个python openid版本。

pip uninstall python-openid
pip uninstall python3-openid

然后卸载social-auth-app-django或类似的应用程序

pip uninstall social-auth-app-django

现在再次安装您的软件包。它应该下载回适当的依赖项。如果没有,您可以随时使用pip install python3-openid

重新安装