1

我正在尝试使用python-social-authDjango 1.9 和 Python 3。据我所知,我已经安装了所有必要的要求,并且在我的settings.py. 但是,当我尝试运行迁移或运行 Django 开发服务器时,我收到以下错误:

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. 这对我不起作用。我还看到了许多与ImportErrors 和相关的帖子python-social-auth,但还没有找到适合我的解决方案。我假设我配置错误/未能配置某些东西,但我不确定是什么。我在这里做错了什么?

4

2 回答 2

5

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

在 python-openid 仍然可用的情况下安装 PSA 时似乎出了点问题。所以一定要删除两个版本,所以 python-openid 和 python3-openid,然后删除 PSA 并尝试重新安装它。在日志中,您现在应该会看到 python3-openid 与 PSA 一起安装。这样做之后,我可以毫无问题地应用所有迁移。

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

希望能帮助到你!

于 2016-08-03T15:01:01.683 回答
3

这发生在我尝试设置时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

于 2019-02-12T13:05:22.020 回答