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:
from google.cloud import language_v1
from google.cloud.language_v1 import enums
from google.cloud.language_v1 import types
[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
Related
In the process of downloading mysql connector, I've taken 3 approaches:-
The commonly advised pip approach where I think the PATH (Python on system; which I don't think I understand) fails me since it doesn't seem to install mysql.connector. It gives a deprecation, collects mysql.connector and launches an error.
Direct download through this site: https://dev.mysql.com/downloads/connector/python/ whereby I've changed security preferences(since it was an unidentified by apple developer) and tried downloading but the application doesn't appear anywhere on my desktop and I can't seem to find it anywhere else.
I followed this link: https://www.youtube.com/watch?v=1ji8lqiBJe0 and everything went fine till 1:34. I don't use pycharm so I decided to directly write import mysql.connector on idle.
At first, it would give me this error:-
Traceback (most recent call last):
File "", line 1, in
import mysql.connector
ModuleNotFoundError: No module named 'mysql
Now it presents this error:-
Traceback (most recent call last):
File "", line 1, in
import mysql.connector
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/init.py", line 41, in
import dns.resolver
ModuleNotFoundError: No module named 'dns'
I can't seem to understand where 'dns module' comes from. Could anybody help me on how to proceed? I think I've exhausted every method at this point but can't find an error.
Have you correctly install dnspython ?
pip install dnspython
https://github.com/rthalley/dnspython
and the connector for your OS
https://dev.mysql.com/downloads/connector/python/
I have tried to get the Alexa ranking for a given website. I used PyPI's seolib library and installed it in my environment using !pip install seolib --user command. After executing alexa_rank = seolib.get_alexa('http://google.com') code line, I got the following error.
ModuleNotFoundError: No module named 'api'
Then I installed api module using !pip install api --user command. Then after I got this import error and I don't have an idea of how to solve this error. Please somebody help on this.
import seolib
alexa_rank = seolib.get_alexa('http://google.com')
print(alexa_rank)
ImportError Traceback (most recent call last)
<ipython-input-21-b46efa0fce9a> in <module>
----> 1 import seolib
2
3 alexa_rank = seolib.get_alexa('http://google.com')
4 print(alexa_rank)
~/.local/lib/python3.7/site-packages/seolib/__init__.py in <module>
4
5
----> 6 from api import get_seomoz_data
7 from api import get_alexa
8 from api import get_semrush
ImportError: cannot import name 'get_seomoz_data' from 'api' (/home/mylap/.local/lib/python3.7/site-packages/api/__init__.py)
I'm using Python 3.7.3 version on my environment.
seolib version 0.1.3, last release was in 2013 year. Homepage returns error 404. Doesn't look good. Old, outdated, abandoned.
The code from api import was relative import in Python 2.7, changed to absolute import in Python 3. Overall the code seems to be Python2-only.
I am trying to send data to the Azure Blob Storage and my first step was to just check the connection by using the sample code I found on the tutorial website:
from azure.storage.blob import BlockBlobService
blob_service = BlockBlobService(account_name, account_key)
blob_service.create_container(
'mycontainername',
public_access=PublicAccess.Blob
)
blob_service.create_blob_from_bytes(
'mycontainername',
'myblobname',
b'<center><h1>Hello World!</h1></center>',
content_settings=ContentSettings('text/html')
)
print(blob_service.make_blob_url('mycontainername', 'myblobname'))
Of course entered the account name and the account key. But I get this error, which I also get when using my own python script so this is a big problem for me:
Traceback (most recent call last):
File "azuretest.py", line 1, in <module>
from azure.storage.blob import BlockBlobService
ImportError: No module named 'azure'
I am a beginner in this topic and I am very lost. Can anyone tell me what to do? Thanks
Installing just the azure-storage library should be sufficient in stead of installing the entire SDK.
pip install azure-storage
Edit
I see you have already done this. The package might not be in your python path. You could try adding
import sys
sys.path.append('/usr/local/lib/python3.6/dist-packages')
at the top of your script (but I am not 100% sure that it will be there on your syste, it is on ubuntu)
or append it to your PYTHONPATH environment variable.
I am trying to import a pypi module (thinkx 1.1.2) into spyder. It is installed on anaconda and showing up on conda list. I my python path folders is my anaconda folder. When I attempt to import thinkx into spyder I get :
import thinkx
Traceback (most recent call last):
File "", line 1, in
import thinkx
ImportError: No module named 'thinkx'
According to module README, thinkx does not expose package named thinkx.
It provides the following modules:
thinkbayes: Code for Think Bayes.
thinkstats2: Code for Think Stats, 2nd edition
thinkbayes2: Code for Think Bayes, 2nd edition, not yet published.
thinkdsp: Code for Think DSP
thinkplot: Plotting code used in all of the books, mostly wrapper functions for matplotlib.pyplot
Try:
import thinkbayes
I'm trying to run the hello world tutorial for the Google app engine in Go language. The GAE SDK for go is based on python 2.5, which I installed. I then had to install openssl, but now when I try to run my sample application on the SDK, I get the following error:
ImportError: No module named _md5
I even tried a simple import md5 & import hashlib from the python interpreter interface, and i still get the same error
>>> import hashlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/hashlib.py", line 133, in <module>
md5 = __get_builtin_constructor('md5')
File "/usr/local/lib/python2.5/hashlib.py", line 60, in __get_builtin_constructor
import _md5
ImportError: No module named _md5
Does anybody know a workaround for this? Thank you!
I have a feeling that this problem is really about python installation than anything else
Your problem has nothing to do with GAE, or the SDK. I have faced this before. If you tried to install your custom version of python (on Ubuntu), then you land up with such issues. You should uninstall the custom python using checkinstall. More details can be found about there here: Uninstall python built from source?.
Just use the default python and you'll be fine!