I am having a lot of trouble with getting the Google Cloud Natural Language API running. I am trying to run a Python program in Linux on a Google VM. I am also unsure of how to run a full Traceback of the error. The following code is not working:
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
.
On Python 2 I get the error:
Traceback (most recent call last):
File "natlangex.py", line 3, in <module>
from google.cloud.language import enums
ImportError: cannot import name enums
I tried upgrading to Python 3 and when I run Python 3 I get the error: And I updated to Python 3. One thing that is confusing is that when I run Python 3 the error is a bit different:
Traceback (most recent call last):
File "natlangex.py", line 2, in <module>
from google.cloud import language
ImportError: No module named 'google'
Here are the other things I have tried:
- I installed the SDK.
- I set
export GOOGLE_APPLICATION_CREDENTIALS="apikey.json"
. - I tried
!pip install google-cloud-language
- I upgraded pip
pip install --upgrade setuptools pip.
I am very lost! Thank you in advance.
It seems that you are using wrong syntax because of the library update, you may refer now to the new one, following [1] and more specifically [2].
It seems that the official Natural Language documentation of Google Cloud is not updated yet [3], but at the end of this documentation you have links to the Python Client Library [1][2] where it explains the changes.
Your imports should be:
[1] https://googleapis.dev/python/language/latest/api.html
[2] https://googleapis.dev/python/language/latest/gapic/v1/api.html
[3] https://cloud.google.com/natural-language/docs/reference/libraries#client-libraries-usage-python