Import Error : No module named django_orm

为君一笑 提交于 2019-12-22 10:28:45

问题


While importing CredentialsField from oauth2client.django_orm, I am getting:

Import Error: No module named django_orm

I've already installed the prerequisites: django-orm and python-oauth2.


回答1:


It looks like there's been a change on the OAuth2 library:

Refactor all django-related code into oauth2client.contrib.django_util. Add DjangoORMStorage, remove FlowField. (#546)

You can check this here.

Perhaps you can try something like this (I don't get any import errors when running it, but I am not sure it works):

from oauth2client.contrib.django_util.storage import DjangoORMStorage
from oauth2client.contrib.django_util.models import CredentialsField



回答2:


Documentation on Drive API Guide isn't upto date (Last updated in May 2015).

Use these imports instead:

from oauth2client.contrib.django_orm import CredentialsField
from oauth2client.contrib.django_orm import FlowField
from oauth2client.contrib.django_orm import Storage

If you're following API Guide, then more imports will break. Developers of oauth2client have moved all non-core modules (django_orm, xsrfutil, appengine, etc.) to contrib. Refer to oauth2client source code if you get more ImportErrors.




回答3:


It looks like the oauth2client library has since been deprecated. Check out the more up to date google-auth library https://google-auth.readthedocs.io

To create a credentials object with an auth token: https://google-auth.readthedocs.io/en/latest/user-guide.html#user-credentials

import google.oauth2.credentials

credentials = google.oauth2.credentials.Credentials(
    'access_token')


来源:https://stackoverflow.com/questions/36317811/import-error-no-module-named-django-orm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!