AttributeError:模块'google.cloud'没有属性'logging'Google Cloud

时间:2018-09-27 22:11:18

标签: python google-cloud-platform pycharm google-authentication

我关注了来自GCP的these tutorials

但是当我运行代码时,出现此错误:

  

client = google.cloud.logging.Client() AttributeError: module 'google.cloud' has no attribute 'logging'

我不明白为什么这样,因为使用pyCharm它向我展示了方法

我的代码:

import unittest
import os
from dotenv import load_dotenv
load_dotenv(verbose=True)
from google.oauth2 import service_account
import google.cloud.logging


import unit_test
script_dir = os.path.dirname(__file__)
file_path = os.path.join(script_dir, os.getenv('FIREBASE_ADMIN_CREDENTIAL_PATH'))
credentials = service_account.Credentials.from_service_account_file(
    file_path)

client = google.cloud.logging.Client()

文件路径: enter image description here

1 个答案:

答案 0 :(得分:1)

您需要在本地环境中安装google-cloud-logging软件包,或将其添加到requirements.txt中,具体取决于您尝试在何处运行代码:

在本地安装:

pip install --upgrade google-cloud-logging

或添加到requirements.txt

google-cloud-logging