简体   繁体   English

导入错误:没有名为django_orm的模块

[英]Import Error : No module named django_orm

While importing CredentialsField from oauth2client.django_orm , I am getting: oauth2client.django_orm导入CredentialsField时,我得到:

Import Error: No module named django_orm

I've already installed the prerequisites: django-orm and python-oauth2 . 我已经安装了先决条件: django-ormpython-oauth2

It looks like there's been a change on the OAuth2 library: 看起来OAuth2库发生了变化:

Refactor all django-related code into oauth2client.contrib.django_util. 将所有与django相关的代码重构为oauth2client.contrib.django_util。 Add DjangoORMStorage, remove FlowField. 添加DjangoORMStorage,删除FlowField。 (#546) (#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

Documentation on Drive API Guide isn't upto date (Last updated in May 2015). 有关Drive API指南的文档不是最新的(最后更新于2015年5月)。

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. 如果您正在关注API指南,那么更多导入将会中断。 Developers of oauth2client have moved all non-core modules (django_orm, xsrfutil, appengine, etc.) to contrib . oauth2client的开发人员已将所有非核心模块(django_orm,xsrfutil,appengine等)移至contrib Refer to oauth2client source code if you get more ImportError s. 如果您获得更多ImportError请参阅oauth2client源代码

It looks like the oauth2client library has since been deprecated. 看起来oauth2client库已被弃用。 Check out the more up to date google-auth library https://google-auth.readthedocs.io 查看最新的google-authhttps://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 要使用身份验证令牌创建凭据对象: https//google-auth.readthedocs.io/en/latest/user-guide.html#user-credentials

import google.oauth2.credentials

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM