ImportError: cannot import name 'metrics' from 'skimage' - python

Here's the part that involves the use of skimage in the code:
from skimage import metrics
....
print(metrics.mean_squared_error(gray_frame, canny_img))
print(metrics.peak_signal_noise_ratio(gray_frame, canny_img))
Here's the error:
C:\Users\user\Desktop>python cannyopencv2.py
Traceback (most recent call last):
File "cannyopencv2.py", line 6, in <module>
from skimage import metrics
ImportError: cannot import name 'metrics' from 'skimage' (C:\ProgramData\Anaconda3\lib\site-packages\skimage\__init__.py)
Please help me get rid of it.

Try to install latest version of skimage because that version does not have that module in it so use below command to upgrade it!
pip install scikit-image -U
or
pip install scikit-image --upgrade

You need to install the package first in order to use it.
pip install scikit-image or pip3 install scikit-image
docs

Related

cannot import sklearn even though it is installed successfully

I have installed sklearn through pip successfully using this command:
$pip install -U scikit-learn
But I cannot import it.
import sklearn
Result:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>
----> 1 import sklearn
ModuleNotFoundError: No module named 'sklearn'
Please help
You might want to try installing scikit-learn: pip install scikit-learn
Try pip3 install sklearn.
This will install the libraries you need for python 3.

Why do I still get the "module not found" error even after having installed the package using pip install?

I am trying to create an image processing program using convolutions. I need the package scikit-image, specifically this:
from skimage.exposure import rescale_intensity
I have repeatedly installed scikit-image using pip install scikit-image in my terminal (Mac). I did this in the folder where my convolutions.py file is located (is this what is meant by the PYTHONPATH?). However, I always get an error message:
Traceback (most recent call last):
File "Convolutions.py", line 6, in <module>
from skimage.exposure import rescale_intensity
ImportError: No module named skimage.exposure
How do I solve the problem?
make sure you are installing the package on the same version of python which you are running. On a mac, python by default runs python-2.7, and the command python3 runs python-3.x. Also, pip by default installs packages to python-2.7. To install them on python3 try running
python3 -m pip install scikit-image
or simply
pip3 install scikit-image

Problem with CV2 : numpy.core.multiarray failed to import

Tried to solve it with :
pip install -U numpy
but it still does not work.
That is what the console shows to me when I try to run the application :
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File "/Users/Rubio/Desktop/logistic-regression/train.py", line 8, in <module>
import cv2
File "/Library/Python/2.7/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
Uninstall & Install Numpy
conda uninstall numpy
conda install -c conda-forge numpy
it works
I had a file named numbers.py in the same folder.
Removing this file solved the issue for me.
Very strange, but worked.
Two solutions. I faced this problem with ai2thor environment.
Just add import numpy.core.multiarray before the import cv2 statement
Update number: pip install -U --no-cache-dir numpy==1.19.3
Reinstall OpenCV:
conda install -c anaconda opencv (for anaconda users)
I discovered that my problem was that I had two versions of numpy installed, I uninstall one of them and it worked normal.
I faced this error with Tello Drone "DJITelloPy" and this solution from Soroush Karimi saved the day.
pip uninstall numpy
pip install numpy==1.19.3

How to install google.cloud with Python pip?

I am relatively new to Python and I am stuck on something which is probably relatively easy to resolve.
I have installed the following packages:
pip install --upgrade google-api-python-client
pip install --upgrade google-cloud
pip install --upgrade google-cloud-vision
In my Python file I have:
import cv2
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
...etc...
And this gives me the error:
Traceback (most recent call last):
File "test.py", line 6, in <module>
from google.cloud import vision
ImportError: No module named 'google.cloud'
What am I missing and where should I look (logs?) to find the answer in the future.
PS:
Pip installs of google-cloud and google-cloud-vision have the output:
Cannot remove entries from nonexistent file /Users/foobar/anaconda/lib/python3.5/site-packages/easy-install.pth
UPDATE:
Running pip freeze doesn't show the packages to be installed...
I had a similar problem. Adding "--ignore-installed" to my pip command made it work for me.
This might be a bug in pip - see this page for more details: https://github.com/pypa/pip/issues/2751
You need to download and install the google-cloud-sdk. Follow this link https://cloud.google.com/sdk/docs/
try this :
from google.cloud.vision import *

Numpy and OpenCV

I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import
So I installed numpy on Ubuntu using:
apt-get install python-numpy
So when I import numpy I get:
Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
I really need help. I'm using Python 2.7.3 on Ubuntu.
There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.
In Ubuntu you can install both dependencies with
sudo apt-get install python-numpy python-opencv
The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:
import numpy
import cv
Hope that helps.
It's better that use some package management tool such like pip to install numpy.
For example,
pip install numpy

Categories