Skip to main content
 首页 » 编程设计

python之属性错误 : module 'google.cloud' has no attribute 'logging' Google Cloud

2024年12月31日9pengyingh

我关注了these tutorials来自 GCP。

但是当我运行代码时,我得到这个错误:

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() 

文件路径:

请您参考如下方法:

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

本地安装:

pip install --upgrade google-cloud-logging 

或者添加到requirements.txt

google-cloud-logging