Python ModuleNotFoundError: No module named 'azure.cognitiveservices' - python

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

Related

ModuleNotFoundError: No module named 'google' while using google-cloud-vision api

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

CONDA Base Env load error / NUMPY: ImportError: DLL load failed

Just installed miniconda on C:\Anaconda 3 and ran conda install numpy unsing the Anaconda shell (defaults to conda base as env).
If I run the Anaconda command prompt and type python >> import numpy all works fine.
If I open a normal command window and got to c:\Anaconda3 and run python >> import numpy this fails (error below).
I have checked sys.path and they are the same on both CMD windows. The only solution is to run on the normal CMD window doing: c:\Anaconda3\Scripts\conda activate base and then run python >> import numpy.
I had Miniconda installations in the past that did not have this issue so I am surprised to suddenly have to activate the environment. I thought the base environment is loaded by default but it seems as if this is not the case and i have to force that.
The error I get is:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "c:\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in
<module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
I found that I could run from the command line: C:\Anaconda3\python.exe C:\Anaconda3\cwp.py C:\Anaconda3 C:\Anaconda3\python.exe and then run import numpy and that will work. The cwp.py file is as follows:
# this script is used on windows to wrap shortcuts so that they are executed within an environment
# It only sets the appropriate prefix PATH entries - it does not actually activate environments
import os
import sys
import subprocess
from os.path import join, pathsep
from menuinst.knownfolders import FOLDERID, get_folder_path, PathNotFoundException
# call as: python cwp.py PREFIX ARGs...
prefix = sys.argv[1]
args = sys.argv[2:]
new_paths = pathsep.join([prefix,
join(prefix, "Library", "mingw-w64", "bin"),
join(prefix, "Library", "usr", "bin"),
join(prefix, "Library", "bin"),
join(prefix, "Scripts")])
env = os.environ.copy()
env['PATH'] = new_paths + pathsep + env['PATH']
env['CONDA_PREFIX'] = prefix
documents_folder, exception = get_folder_path(FOLDERID.Documents)
if exception:
documents_folder, exception = get_folder_path(FOLDERID.PublicDocuments)
if not exception:
os.chdir(documents_folder)
sys.exit(subprocess.call(args, env=env))
PS: If you wonder "why is this needed if you can simply activate base"? When using xlwings for instance the script calls python.exe (without activating an environment first, even if I thought that using the python.exe on the root folder meant you did not need to activate base environment). This is troublesome as I get the error when I try to load numpy.
Thanks!
It's a DLL error. caused because of missing DLL file. download files from here
Go to C:/windows/system32 and /Windows/SysWOW64 folder .just paste those files
If asked just replace files

Python ModuleNotFoundError of own modules (external anaconda)

So I have the infamous ModuleNotFoundError, and for a couple of hours I can't find the solution. I know that my project works in Pycharm but I wanted to set it up in Visual Studio Code.
the error
(base) C:\pythonprojects\AI_Project>C:/Users/quint/Anaconda3/python.exe c:/pythonprojects/AI_Project/be/kdg/MarkovDecisionProcess/Main.py
Traceback (most recent call last):
File "c:/pythonprojects/AI_Project/be/kdg/MarkovDecisionProcess/Main.py", line 1, in <module>
import be.kdg.MarkovDecisionProcess.Agent as Agent
ModuleNotFoundError: No module named 'be'
My project structure
project
|__be
|__kdg
|__MarkovDecisionProcess
|__Agent.py
|__Main.py
|__Percept.py
in main.py
import be.kdg.MarkovDecisionProcess.Agent as Agent
import be.kdg.MarkovDecisionProcess.Percept as Percept
import gym as gym
import numpy as np
...
in Agent.py
import gym
import numpy as np
from be.kdg.MarkovDecisionProcess.Percept import Percept
class Agent:
def __init__(self, stateRewards, state_count, action_count):
...
my environment: Python 3.6.5 ('base':conda)
python path
"python.pythonPath": "C:\\Users\\quint\\Anaconda3\\python.exe"
First I had __Init__.py in every dir, but then I read here http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html that this also could be an issue.
I will be alert for any suggestions and will try them as I read them.
Thanks in advance :-)
You first have to add __init__.py to your MarkovDecisionProcess to make it a module. Then, you have to add \path\to\project to PYTHONPATH for you to import.
For example, in Windows:
setx PYTHONPATH /M "\path\to\project"
In Unix/macOS:
PYTHONPATH=$PYTHONPATH:/path/to/project
Then, you can import like this: from be.kdg.MarkovDecisionProcess import Agent
Alternatively, you can use importlib.util
if you want to import Agent in Main.py just use
import Agent
because which is in the same directory

Unable to import storage from google.cloud

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

Error: No module named 'fcntl'

I get the following error:
Traceback (most recent call last):
File "C:/Users/aaaa/Desktop/ttttttt.py", line 5, in <module>
import reload
File "C:\Users\aaa\AppData\Local\Programs\Python\Python36\lib\site-
packages\reload.py", line 3, in <module>
import sys, time, re, os, signal, fcntl
ModuleNotFoundError: No module named 'fcntl'
So I did a pip install, which also gets an error.
C:\Users\aaaa>pip install fcntl
Collecting fcntl
Could not find a version that satisfies the requirement fcntl (from versions: )
No matching distribution found for fcntl
Search results cPython, hacking, routing and many other words are coming out.
It's a tough answer for beginners, so I want to get a more detailed solution.
How should I solve it?
#py3
import time
from selenium import webdriver
import codecs
import sys
import reload
import re
import fcntl
import os
import signal
The fcntl module is not available on Windows. The functionality it exposes does not exist on that platform.
If you're trying to lock a file, there are some other Python modules available which provide that functionality. One I've seen referenced in other answers is portalocker.
I got the same error when trying to run my flask app using gunicorn.
gunicorn --bind 127.0.0.1:5000 predict:app
The issue is that 'fcntl' is not available on windows. The alternative that can be used, as suggested by Alexey Grigorov in Ml bookcamp, is the 'waitress' package.
pip install waitress
Then write in the command prompt the following command.
waitress-serve --listen=127.0.0.1:5000 predict:app
For those still looking for the answer.
I got some info from this website https://pypi.org/project/micropython-fcntl/#files and installed as follows which solved the problem:
pip install micropython-fcntl
What you can do is install importlib with the usual:
pip install importlib
From there use the following:
from importlib import reload
Note that you will need to load your imports as 'modules':
from petshop import parrot as parrot

Categories