0

I am trying to figure out how to use google cloud translate in my own Python3 environment. I have completed the codelabs tutorial that shows me how to do it in the cloud shell, but I want to run it from my own environment. I can install the google-cloud-translate library of course but I have no idea how to set up authentication, which in the tutorial uses a bunch of cloud shell commands that (AFAIK) I can't run from my Linux shell.

I did get a copy of the key.json file created in that process, in hopes there is a way to use that for my standalone system. But after quite a bit of searching I've not found any instructions for setting up authentication using that file or otherwise. There is a guide for setting up a Python dev environment, but it says nothing about authentication.

Can anyone point me to a tutorial or worked example?

Jofre
  • 3,718
  • 1
  • 23
  • 31
Steve
  • 945
  • 3
  • 13
  • 22
  • You can surely install gcloud in [linux](https://cloud.google.com/sdk/docs/install#deb). Or alternatively you can do everything they do in this lab [related to enabling things] in google cloud console (Web UI) instead. If stuck, let us know which gcloud command you struggle with. – jabbson Mar 20 '21 at 02:12
  • OK got gcloud SDK installed. Two questions. (1) When I gave my phone number for login, it logged me into a different google id than the one I completed the lab on, and for which I have the $300 free trial. How to get to that account? (2) So all I need to do is run the same steps in the lab using this gcloud instead? – Steve Mar 20 '21 at 20:21
  • The gcloud in cloud shell isn't any different from the one you now have on your computer, so yes, just use it the same way. As for the account - only you would know. When you register, I believe you always provide your email address, and thus you should have registration email in your inbox. – jabbson Mar 20 '21 at 21:13
  • OK got it configured with the right account. Now to the step in the lab where is starts installing python packages. Another doc https://cloud.google.com/python/docs/setup says to install python packages using venv, but the lab doesn't do that. Should I do it? If so the first step is "cd your-project". Is that the gcloud project name? I have no dir by that name. – Steve Mar 20 '21 at 22:14
  • This is very much python related. If you want to work in the venv (good practice) - do so, otherwise, work with the system-wide python. As for where to cd or what to do, I think the best thing is to understand why you are doing certain things, because there is no one recipe to go about creating a project. – jabbson Mar 20 '21 at 22:50
  • Any updates on this, if so, could you provide it as an answer? If not, could you update me on the issues you're having now to keep troubleshooting? – Daniel Gomez Apr 29 '21 at 07:54

1 Answers1

0

You can first install Cloud SDK, like someone on the comments said.

After that, to authenticate I would set up the GOOGLE_APPLICATION_CREDENTIALS environment variable with the path to your service account key

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/my/service-account-key.json"

You can add it to your .bashrc if you don't want to run it each time you log in

Daniel Gomez
  • 178
  • 6