-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translation: AttributeError: module 'google.cloud.translate' has no attribute 'Client' #9545
Comments
I've had the same problem
I am running Python 3.7.3 I'm using the demo code from I believe I have all the correct dependencies installed Requirement already satisfied, skipping upgrade: google-api-core[grpc]<2.0.0dev,>=1.14.0 in ./venv/lib/python3.7/site-packages (from google-cloud-translate) (1.14.3) |
I am experiencing the exact same thing.. from google.cloud import translate translate_client = translate.Client() File "", line 1, in AttributeError: module 'google.cloud.translate' has no attribute 'Client' |
Hi, If I move the same script in a folder where I did the same steps 2-3 months ago, it works instead! Python 3.6.8 (default, Oct 7 2019, 12:59:55)
|
Hi all, a new major version was released recently: #9527 To keep your client code working as expected you can do one of 2 things:
or
|
@nnegrey Was there a deprecation warning on this? Perhaps there was but I missed it... |
Also looks like your documentation on PyPi is out of date: >>> from google.cloud import translate
>>> client = translate.Client() |
Apologies for any confusion caused by the README. I've opened #9536 to fix that and some other issues with the docs. Please reference the
As far as deprecation warning: We released this as a major version bump 1.7.0 -> 2.0.0 to indicate that there were breaking changes. We follow the semantic versioning specification (semver.org). Changes are noted in the CHANGELOG.md and the release notes on GitHub For GA libraries (versions >=1.0.0) please make sure to (1) pin to a specific version or (2) specify a version range less than the next major version. Otherwise you can end up installing a version of this library that is incompatible with your codebase. (1) pin to a specific version that you know works with your code
(2) specify a version range less than next major
|
I can confirm that this code makes it work
Might need to update the quick start guide https://cloud.google.com/translate/docs/quickstart-client-libraries#client-libraries-install-python |
@alecthegeek, yep! Also updated the docs site this morning. |
Thanks for the super prompt followup, guys. This indeed solved it for me: from google.cloud import translate_v2 as translate For what it's worth, I get the semantic versioning bit and how a major release should expect to come with breaking changes, but I was surprised there were no In any case, thanks for the very quick responses. We appreciate the work you put into this package! |
Edit: nevermind, migrating to the v3 API is a bad idea. The new API is computer generated Python code, not designed for use by humans. It's significantly worse, I regret using it. Just change the import statement to use the Converting calls to
An example: from pathlib import Path
import json
from google.cloud.translate import TranslationServiceClient
from google.oauth2 import service_account
GOOGLE_TRANSLATE_CREDENTIALS_FILE = "creds.json"
GOOGLE_TRANSLATE_CREDENTIALS = service_account.Credentials.from_service_account_file(
GOOGLE_TRANSLATE_CREDENTIALS_FILE
)
GOOGLE_TRANSLATE_PROJECT_ID = "projects/" + GOOGLE_TRANSLATE_CREDENTIALS.project_id
translate_client = TranslationServiceClient(credentials=GOOGLE_TRANSLATE_CREDENTIALS)
supported_languages = {
l.language_code
for l in translate_client.get_supported_languages(
GOOGLE_TRANSLATE_PROJECT_ID
).languages
}
result = translate_client.translate_text(
["I spent a lot of time on this."],
target_language_code="ru",
source_language_code="en",
parent=GOOGLE_TRANSLATE_PROJECT_ID,
)
print([t.translated_text for t in result.translations][0]) |
@verhovsky Thanks for posting that migration guide! |
I could not have got v3 working without the help from @verhovsky above. Just one thing: I needed translate_text( |
It worked for me |
solution is to upgrade google-cloud-translate |
i made a virtual env also tried global env but the error is same.i have tried google logging as well but error is same.using this sample code.
The text was updated successfully, but these errors were encountered: