Opencv python cv2 code ,"cv2 has no attribute .__version__" error - python-3.x

I can successfully get the cv2 version from command line:
>>> import cv2
>>> cv2.__version__
'3.4.4'
But not when I run a script with that code in the Python 3.7.1 Shell (see image here)
import cv2
print (cv2.__version__)
Traceback (most recent call last):
File "B:\Users\Ravi\Desktop\Opencv2\cv2.py", line 1, in <module>
import cv2
File "B:\Users\Ravi\Desktop\Opencv2\cv2.py", line 2, in <module>
print (cv2.__version__)
AttributeError: module 'cv2' has no attribute '__version__'
How can I solve this problem? Not only the version but none of cv2 code works.

Related

ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

I have a simple python program which I am running on a Mac machine.
import numpy as np
def main():
print("np arr test")
arr = np.array([1.0, 2.0, 3.0])
print(arr)
if __name__ == "__main__":
main()
I've verified that the numpy library was correct installed through pip
pip3 list | grep numpy
msgpack-numpy 0.4.4.3
numpy 1.16.2
numpydoc 0.8.0
I get the following error when I run the program
Traceback (most recent call last):
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Volumes/workplace/RPAsosDevelopmentWS/src/RPAsosDevelopmentPy/src/rp_asos_development_py/adhoc_dev/float_nan_test.py", line 1, in <module>
import numpy as np
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/core/__init__.py", line 50, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.6 from "/usr/local/bin/python3.6"
* The NumPy version is: "1.18.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
Process finished with exit code 1
Can you please help me figure out what I am missing? Appreciate your response!
NOTE : Based on the stack overflow post I updated the numpy through the following command
pip3 install numpy --upgrade
pip3 list | grep numpy
msgpack-numpy 0.4.4.3
numpy 1.21.2
numpydoc 0.8.0
WARNING: You are using pip version 21.2.1; however, version 21.2.4 is available.
However I still see the error message
Try to uninstall numpy and install it again.

error while "from sklearn import datasets"

from sklearn import datasets
When running the above code, I got an error:
`Traceback` (most recent call last):
File "perceptron_ml.py", line 2, in <module>
from sklearn import datasets
File "/home/remember/.local/lib/python3.6/site-packages/sklearn/datasets/__init__.py", line 22, in <module>
from ._twenty_newsgroups import fetch_20newsgroups
File "/home/remember/.local/lib/python3.6/site-packages/sklearn/datasets/_twenty_newsgroups.py", line 45, in <module>
from ..feature_extraction.text import CountVectorizer
File "/home/remember/.local/lib/python3.6/site-packages/sklearn/feature_extraction/__init__.py", line 8, in <module>
from ._hashing import FeatureHasher
ImportError: cannot import name 'FeatureHasher'
Ubuntu: 18.04, Python: 3.6.9, Numpy: 1.17.4, scikit-learn: 0.22
The error is due to a glitch happening during the update due to pip. Related SO post is https://stackoverflow.com/a/59355676/6513708
But long story short, you need to remove the following files which were let by pip during the update:
~/.local/lib/python3.6/site-packages/sklearn/decomposition/_online_lda.cpython-36m-x86_64-linux-gnu.so
~/.local/lib/python3.6/site-packages/sklearn/feature_extraction/_hashing.cpython-36m-x86_64-linux-gnu.so
~/.local/lib/python3.6/site-packages/sklearn/datasets/_svmlight_format.cpython-36m-x86_64-linux-gnu.so

Statsmodels.api doesn't import

That's it. It installs, I can import statsmodels, but statsmodels.api doesn't import.
I've tried installing with pip and conda, both give me version 0.9.0 and everything is fine.
I've installed all the dependencies, statsmodels works, but statsmodels.api doesn't.
import statsmodels.api Traceback (most recent call last): File "", line 1, in File
"C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\statsmodels\api.py",
line 16, in
from .discrete.discrete_model import (Poisson, Logit, Probit, File
"C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\statsmodels\discrete\discrete_model.py",
line 45, in
from statsmodels.distributions import genpoisson_p File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\statsmodels\distributions__init__.py",
line 2, in
from .edgeworth import ExpandedNormal File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\statsmodels\distributions\edgeworth.py",
line 7, in
from scipy.misc import factorial ImportError: cannot import name 'factorial' from 'scipy.misc'
(C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\misc__init__.py)
From the error it looks as though there is not a function called factorial within the misc directory of the scipy package.
Have you tried opening up the __init__.py file specified in the error and looking through the misc directory to find the factorial function?

python3 - ImportError: cannot import name '_imaging'

I am getting the following error:
Traceback (most recent call last):
File "./Logic/model.py", line 12, in <module>
from PIL import Image, ImageFilter
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 66, in <module>
from PIL import _imaging as core
ImportError: cannot import name '_imaging'
I don't have PIL installed but I have pillow installed
what to do?

how am i able to import matplotlib without an error

i have tried several times to import matplotlib and remove reinstall all of the possible combinations
i am using conda as package management system, and pip points to conda
trying to run following programm:
import matplotlib.pyplot as plt
or just:
import matplotlib
creates following result:
Traceback (most recent call last):
File "C:/Users/Name/IdeaProjects/zzArchiv/Robot project/RobotProject/DeepLearning/approaches/hvasstutorial/anothermain.py", line 22, in <module>
import matplotlib.pyplot as plt
File "D:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 127, in <module>
from . import cbook
File "D:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 2640, in <module>
class _StringFuncParser(object):
File "D:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 2652, in _StringFuncParser
_funcs['quadratic'] = _FuncInfo(np.square,
AttributeError: module 'numpy' has no attribute 'square'
i googled a lot and searched left and right, but couldn't get any working solutions (most tell to remove and reinstall numpy/matplotlib which i did several times) please help, if you have any clues
thanks

Resources