i ran the following code
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
# Instantiates a client
client = vision.ImageAnnotatorClient()
# The name of the image file to annotate
file_name = os.path.abspath('resources/wakeupcat.jpg')
# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
# Performs label detection on the image file
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description)
the error i get is the following
Traceback (most recent call last):
File "F:\coding\pythonfolder\main.py", line 4, in <module>
from google.cloud import vision
ModuleNotFoundError: No module named 'google'
the library is installed is the following
pip install google-cloud-vision
I am fairly new to the google vision api so maybe there's some point I am missing
kindly let me know what the issue is, I tried pip install --upgrade google-cloud-vision as well but does not seems to work
my python version is Python 3.10.0
kindly let me know if there's any issue or missing information in my question
thank you!!
I'm pretty sure you messed up with the venv, since it worked fine for me. Try using PyCharm (if you don't already do) and setup a venv, or install virtualenv and launch these commands inside your project folder:
virtualenv venv
source venv/bin/activate
pip install google-cloud-vision
python your_file.py
deactivate
Last one is to properly exit the venv
Related
I am following the tutorial from Microsoft ( https://learn.microsoft.com/nl-nl/azure/cognitive-services/Computer-vision/quickstarts-sdk/client-library?pivots=programming-language-python ) to use cognitive service. I use herefor Visual Code and install the Azure with pip using the commandline:
pip install azure-cognitiveservices-vision-customvision
I use the first peace of code(see code below) and try to run the code. But it returns the follwowing error:
(myvenv) PS C:\Users\erikh\OneDrive\Documenten\Git\Python Testlab> & "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/myvenv/Scripts/python.exe" "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/readText.py"
Traceback (most recent call last):
File "c:/Users/erikh/OneDrive/Documenten/Git/Python Testlab/readText.py", line 1, in <module>
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
ModuleNotFoundError: No module named 'azure.cognitiveservices'
And here is the code which i try to execute:
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials
from array import array
import os
from PIL import Image
import sys
import time
# Add your Computer Vision subscription key to your environment variables.
if 'COMPUTER_VISION_SUBSCRIPTION_KEY' in os.environ:
subscription_key = os.environ['COMPUTER_VISION_SUBSCRIPTION_KEY']
else:
print("\nSet the COMPUTER_VISION_SUBSCRIPTION_KEY environment variable.\n**Restart your shell or IDE for changes to take effect.**")
sys.exit()
# Add your Computer Vision endpoint to your environment variables.
if 'COMPUTER_VISION_ENDPOINT' in os.environ:
endpoint = os.environ['COMPUTER_VISION_ENDPOINT']
else:
print("\nSet the COMPUTER_VISION_ENDPOINT environment variable.\n**Restart your shell or IDE for changes to take effect.**")
sys.exit()
I can reproduce your issue, you installed the wrong package, it should be azure-cognitiveservices-vision-computervision instead of azure-cognitiveservices-vision-customvision.
Run the line below, then it will work fine.
pip install azure-cognitiveservices-vision-computervision
New to Python..., well actually new to programming in general, so pls bear with me. On Ubuntu 20.04 (yes, new to Linux as well) with Python 3.8.2
I'm trying to run a script that uses PyPDF2. I was able to install it just fine with:
sudo apt-get install python3-pypdf2
and I can import it from the command line without any error:
import PyPDF2
When i try to import it from Pycharm, however, it generates a ModuleNotFoundError error:
Traceback (most recent call last):
File "/home/surista/.config/JetBrains/PyCharm2020.1/scratches/scratch_2.py", line 1, in <module>
from PyPDF2 import PdfFileReader
ModuleNotFoundError: No module named 'PyPDF2'
Here's the script I'm using.
from PyPDF2 import PdfFileReader
def get_info(path):
with open(path, 'rb') as f:
pdf = PDFFileReader(f)
info = pdf.getDocumentInfo()
number_of_pages = pdf.getNumPages()
print(info)
author = info.author
creator = info.creator
producer = info.producer
subject = info.subject
title = info.title
if __name__ == '__main__':
path = '/home/surista/Documents/pdfs/test_eng-1.pdf'
get_info(path)
Probably missing something obvious here, but any help would be appreciated.
First of all you should install python packages via pip. Run pip install PyPDF2, that might fix it already.
Also check which interpreter is selected for your project in pycharm. If Pycharm isn't using your system python, it won't see packages installed from a normal shell.
You'll find it in the Settings -> Project: your_project -> Project Interpreter.
I use python-pcl and want to load a pcd file.
My code is :
cloud_blob = pcl.load('./Downloads/table_scene_lms400.pcd')
this code works fine in shell, but in Pycharm always have error:
[pcl::PCDReader::readHeader] Could not find file './Downloads/table_scene_lms400.pcd'
I don't know why.
First install pypcd
pip install pypcd
Then run:
import pypcd
pc = pypcd.PointCloud.from_path('table_scene_lms400.pcd')
Reference taken from here
I'm new to Google Cloud Platform, and have uploaded some machine learning code on Jupyter notebook in DataLab.
My issue is although, I installed Google Cloud Storage (using the command: pip install --upgrade google-cloud-storage), I'm unable to import this.
The following is how I'm importing this package:
>>import numpy
>>import pandas as pd
>>from google.cloud import storage
But I'm getting the following error:
ImportErrorTraceback (most recent call last)
in ()
----> 1 from google.cloud import storage
ImportError: cannot import name storage
Note:
This is the content of my JSON config file: {"TokenSources":["env"]}
I tried export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json", but the error persists.
I verified that this package is indeed installed in my environment by typing pip freeze in the command shell:
google-cloud==0.34.0
google-cloud-datastore==1.7.0
google-cloud-spanner==1.4.0
google-cloud-storage==1.10.0
What am I missing here?
Have you installed the google-cloud-storage package in your DataLab environment, or on your local machine? You'll need to run the following command within DataLab:
!pip install google-cloud-storage
See https://cloud.google.com/datalab/docs/how-to/adding-libraries for more details
Also, the google-cloud package is deprecated, you shouldn't need to install it, see https://pypi.org/project/google-cloud/.
So I got it working upon importing storage as follows:
import google.datalab.storage as storage
To make your notebooks resilient to both datalab and non-datalab environments you can use one of the the following methods for handling your import statements:
try:
from google.cloud import storage
except ImportError:
from google.datalab import storage
or
if 'google.datalab' in sys.modules:
from google.datalab import storage
else:
from google.cloud import storage
Alternatively if you would like to switch datalab to using from google.cloud import storage
Run the following in a cell
!pip install google-cloud-storage
Followed by this cell to reset the IPython kernel
# Reset the IPython kernel
from IPython.core.display import HTML
HTML("<script>Jupyter.notebook.kernel.restart()</script>")
Note: You need to reset the Python kernel after installation otherwise you will a ContextualVersionConflict error from naming conflicts
I am having the same problem as this thread regarding twilio-python:
twilio.rest missing from twilio python module version 2.0.8?
However I have the same problem but I have 3.3.3 installed. I still get "No module named rest" when trying to import twilio.rest.
Loading the library from stand alone python script works. So I know that pip installing the package worked.
from twilio.rest import TwilioRestClient
def main():
account = "xxxxxxxxxxxxxxxx"
token = "xxxxxxxxxxxxxxxx"
client = TwilioRestClient(account, token)
call = client.calls.create(to="+12223344",
from_="+12223344",
url="http://ironblanket.herokuapp.com/",
method="GET")
if __name__ == "__main__":
main()
but this does not work:
from twilio.rest import TwilioRestClient
def home(request):
client = TwilioRestClient(account, token)
Do you have any idea what I can try next?
I named a python file in my project twilio.py. Since that file was loaded first, then subsequent calls to load twilio would reference that file instead of the twilio library.
TLDR: just don't name your python file twilio.py
Check which versions of pip and python you are running with this command:
which -a python
which -a pip
pip needs to install to a path that your Python executable can read from. Sometimes there will be more than one version of pip like pip-2.5, pip-2.7 etc. You can find all of them by running compgen -c | grep pip. There can also be more than one version of Python, especially if you have Macports or brew or multiple versions of Python installed.
Check which version of the twilio module is installed by running this command:
$ pip freeze | grep twilio # Or pip-2.7 freeze etc.
The output should be twilio==3.3.3.
I hope that helps - please leave a comment if you have more questions.
This Worked For me : (Windows)
Python librarys are in G:\Python\Lib
(Python is installed at G:, it might be different for you)
Download Twilio from github at paste the library at >> G:\Python\Lib <<
import problem gone :)
I had the same issue and it drove me crazy. Finally I figured it out. When you get the error:
AttributeError: module 'twilio' has no attribute 'version'
Look 2 lines above and the error is telling you where it expects to find the twilio file. So I moved it from where it was to where it was asking it to be.
Installed to:
c:\users\rhuds\appdata\local\programs\python\python37-32\lib\site-packages
Moved it to:
Traceback (most recent call last):
File "", line 1, in
import twilio
File "C:\Users\rhuds\AppData\Local\Programs\Python\Python37-32\twilio.py", line 2, in
Now I can import twilio. Besides that, the only other thing I did was uninstall old versions of Python, but I don't think that really mattered.