[英]Getting error ModuleNotFoundError: No module named 'rest_framework_sso'
I am following https://pypi.org/project/djangorestframework-sso/ tutorial for sso authentication in django, In first step they added 'rest_framework_sso' in INSTALLED_APPSin settings.py without installing any such liberary.我正在关注https://pypi.org/project/djangorestframework-sso/ django中的 sso 身份验证教程,在第一步中,他们在 INSTALLED_APPSin settings.py 中添加了“rest_framework_sso”而不安装任何此类库。 When I tried to do the same I got:
当我尝试做同样的事情时,我得到了:
ModuleNotFoundError: No module named 'rest_framework_sso'
Then I tried pip/pip3 install 'rest_framework_sso' but I got:然后我尝试了 pip/pip3 install 'rest_framework_sso' 但我得到了:
ERROR: Could not find a version that satisfies the requirement rest_framework_sso (from versions: none)
ERROR: No matching distribution found for rest_framework_sso
Then I installed django rest framework but it is stil not working.然后我安装了 django rest 框架,但它仍然无法正常工作。
I want to know why is it not working and how can I solve this, I didn't found anything that can help me related to this.我想知道为什么它不起作用以及如何解决这个问题,我没有找到任何可以帮助我解决这个问题的东西。
(For the wiki-aspect, I'll write down a proper answer in case someone comes by the question later) (对于维基方面,我会写下一个正确的答案,以防以后有人提出问题)
We have to differentiate between two things here: The name of the package on Pypi, which is what you have to use with pip
, and the name of the python module that is provided in that package. We have to differentiate between two things here: The name of the package on Pypi, which is what you have to use with
pip
, and the name of the python module that is provided in that package.
For the django rest framework SSO package, the Pypi package name currently is djangorestframework-sso
, so that has to be used with pip For the django rest framework SSO package, the Pypi package name currently is
djangorestframework-sso
, so that has to be used with pip
pip install djangorestframework-sso
However, the python module that this allows you to use is named rest_framework_sso
, so when adding this to the INSTALLED_APPS
or using it in any other way in python, you need to use this name, as demonstrated in the documentation:但是,允许您使用的 python 模块名为
rest_framework_sso
,因此当将其添加到INSTALLED_APPS
或在 python 中以任何其他方式使用它时,您需要使用此名称,如文档中所示:
from rest_framework_sso.views import obtain_session_token
# go on to use obtain_session_token
If you wonder, there is a questions about why this is the case如果您想知道,有一个关于为什么会这样的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.