配置 Google 在 Windows 上翻译
Configuring Google Translate on Windows
我想在我的 Python 应用程序中使用 Google 翻译 API,我已经通读了文档,设置了我的服务帐户并下载了 JSON现在根据我应该 运行 a:
的文档提交文件
$ export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>
现在我在 Windows 机器上进行开发,我尝试使用
>setx GOOGLE_APPLICATION_CREDENTIALS "<path_to_service_account_file>"
它生成了成功,但是当我尝试创建一个翻译对象时,我不断收到以下错误:
from google.cloud import translate
trans = translate.Client()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\translate\client.py", line 66, in __init__
super(Client, self).__init__(credentials=credentials, _http=_http)
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\client.py", line 128, in __init__
credentials = get_credentials()
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\credentials.py", line 39, in get_credentials
credentials, _ = google.auth.default()
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\auth\_default.py", line 282, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credential and re-run the application. For more
information, please see
https://developers.google.com/accounts/docs/application-default-credentials.
您的问题已在评论中得到解答!下次不要在命令周围使用引号字符。
setx GOOGLE_APPLICATION_CREDENTIALS <path_to_service_account_file>
我想在我的 Python 应用程序中使用 Google 翻译 API,我已经通读了文档,设置了我的服务帐户并下载了 JSON现在根据我应该 运行 a:
的文档提交文件$ export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>
现在我在 Windows 机器上进行开发,我尝试使用
>setx GOOGLE_APPLICATION_CREDENTIALS "<path_to_service_account_file>"
它生成了成功,但是当我尝试创建一个翻译对象时,我不断收到以下错误:
from google.cloud import translate
trans = translate.Client()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\translate\client.py", line 66, in __init__
super(Client, self).__init__(credentials=credentials, _http=_http)
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\client.py", line 128, in __init__
credentials = get_credentials()
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\credentials.py", line 39, in get_credentials
credentials, _ = google.auth.default()
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\auth\_default.py", line 282, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credential and re-run the application. For more
information, please see
https://developers.google.com/accounts/docs/application-default-credentials.
您的问题已在评论中得到解答!下次不要在命令周围使用引号字符。
setx GOOGLE_APPLICATION_CREDENTIALS <path_to_service_account_file>