安装 Google Cloud SDK
支持的 Python 版本 Python 3(3.5 到 3.9)。
运行 PowerShell 命令:
(New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:Temp\GoogleCloudSDKInstaller.exe")& $env:Temp\GoogleCloudSDKInstaller.exe
安装时,取消选择”Bundled Python”选项
打开Google Cloud SDK Shell
(按照以下步骤输入) port和address改为自己实际代理情况
Welcome to the Google Cloud SDK! Run "gcloud -h" to get the list of available commands.
---
D:\Programming\Tools\cloud\google_cloud\cloud_sdk>gcloud config set proxy/type socks5
Updated property [proxy/type].
D:\Programming\Tools\cloud\google_cloud\cloud_sdk>gcloud config set proxy/address 127.0.0.1
Updated property [proxy/address].
D:\Programming\Tools\cloud\google_cloud\cloud_sdk>gcloud config set proxy/port 1080
Updated property [proxy/port].
D:\Programming\Tools\cloud\google_cloud\cloud_sdk>gcloud init
Welcome! This command will take you through the configuration of gcloud.
Settings from your current configuration [proxyconfig0] are:
core:
disable_usage_reporting: 'False'
proxy:
address: 127.0.0.1
port: '1080'
type: socks5
Pick configuration to use:
[1] Re-initialize this configuration [proxyconfig0] with new settings
[2] Create a new configuration
[3] Switch to and re-initialize existing configuration: [default]
Please enter your numeric choice: 1
Your current configuration has been set to: [proxyconfig0]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
You must log in to continue. Would you like to log in (Y/n)? y
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&prompt=select_account&response_type=code&client_id=32555940559.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&access_type=offline
You are logged in as: [dreammax1997@gmail.com].
Pick cloud project to use:
[1] tonal-run-227315
[2] Create a new project
Please enter numeric choice or text value (must exactly match list
item): 1
Your current project has been set to: [tonal-run-227315].
Do you want to configure a default Compute Region and Zone? (Y/n)? y
Which Google Compute Engine zone would you like to use as project
default?
If you do not specify a zone via a command line flag while working
with Compute Engine resources, the default is assumed.
[1] us-east1-b
[2] us-east1-c
[3] us-east1-d
[4] us-east4-c
Too many options [56]. Enter "list" at prompt to print choices fully.
Please enter numeric choice or text value (must exactly match list
item): 1 (根据实际情况选)
Your project default Compute Engine zone has been set to [us-east1-b].
You can change it by running [gcloud config set compute/zone NAME].
Your project default Compute Engine region has been set to [us-east1].
You can change it by running [gcloud config set compute/region NAME].
Created a default .boto configuration file at [C:\Users\DreamMax\.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!
* Commands that require authentication will use dreammax1997@gmail.com by default
* Commands will reference project `tonal-run-227315` by default
* Compute Engine commands will use region `us-east1` by default
* Compute Engine commands will use zone `us-east1-b` by default
要谷歌账号绑定信用卡,免费试用12个月,300$赠金。
详细见:Google Cloud_google cloud 永久免费_dufufd的博客-CSDN博客
设置应用默认凭据(本地开发环境)
在Google Cloud SDK shell里运行
创建凭据文件:gcloud auth application-default login
创建服务帐号密钥并将其提供给 ADC
对于 PowerShell:
$env:GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"
将 KEY_PATH 替换为包含您的服务帐号密钥的 JSON 文件的路径。
例如:$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
来源:https://cloud.google.com/docs/authentication/provide-credentials-adc?hl=zh-cn#local-dev
配置完应用默认凭据后可以使用情感分析,详细举例流程见:https://cloud.google.com/natural-language/docs/sentiment-tutorial?hl=zh-cn