How to solve the import cv problem in vs studio? - python-3.x

File "c:\Users\csany\Documents\PYTHON_BEGINEERS\read.py", line 1, in
import cv2 as cv
File "C:\Users\csany\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2_init_.py", line 5, in
from .cv2 import *
ImportError: DLL load failed while importing cv2: The specified module could not be found.
Every time I try to run the code i get this error. I have installed OpenCV module through its source I have changed its path yet it still won't work in vs studio for python. Please help me out

You can download the latest OpenCV 3.2.0 for Python 3.6 on Windows 32-bit or 64-bit machine, look for file starts withopencv_python‑3.2.0‑cp36‑cp36m, from this unofficial site. Then type below command to install it:
pip install opencv_python‑3.2.0‑cp36‑cp36m‑win32.whl (32-bit version)
pip install opencv_python‑3.2.0‑cp36‑cp36m‑win_amd64.whl (64-bit version)
I think it would be easier.
Update on 2017-09-15:
OpenCV 3.3.0 wheel files are now available in the unofficial site and replaced OpenCV 3.2.0.
Update on 2018-02-15:
OpenCV 3.4.0 wheel files are now available in the unofficial site and replaced OpenCV 3.3.0.
Update on 2018-06-19:
OpenCV 3.4.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.0.
Update on 2018-10-03:
OpenCV 3.4.3 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.1.
Update on 2019-01-30:
OpenCV 4.0.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.
Update on 2019-06-10:
OpenCV 3.4.6 and OpenCV 4.1.0 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.
src : https://stackoverflow.com/a/43190144/13319197

Related

Python and SpaCy - cannot download specific version

I am using Python 3.7.7
I ran the following (after pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz) and got results
[XXXXX#localhost some-folder]$ python3 -m spacy download en_core_web_sm-2.2.0
2021-02-16 17:58:24.921639: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2021-02-16 17:58:24.921671: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. Ignoring the CUDA*.
No compatible package found for 'en_core_web_sm-2.2.0
the only way I have made it to work is to remove the version 2.2.0 from the code. But SpaCy documentation suggests that the version number should be able to download the correct file.
So, what am I doing wrong ?
Your spacy version also matters, not only the Python version.
spaCy models-languages compatibility
If you are already using spaCy v3, you won't be able to download language versions < 3

Why do I get an ImportError for opencv2 when I run on python3.7.3?

I'm trying to import opencv2 using python3.7.3 on Mac OS 10.10 but an ImportError occurs. How should I solve it?
I tried to install opencv3 using pip, pip3, and homebrew. Probably not install right.
import cv2
import numpy as np
import sys
import pytesseract as py
import matplotlib.pyplot as plt
Error
Traceback (most recent call last):
File "/Users/wujian/Desktop/Project/Proj.py", line 1, in <module>
import cv2
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cv2/cv2.cpython-37m-darwin.so, 2): Symbol not found: _clock_gettime
Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cv2/.dylibs/libavutil.56.22.100.dylib (which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cv2/.dylibs/libavutil.56.22.100.dylib
The issue seems to be (oddly) related to your copy of libavutil which is part of ffmpeg.
It's hinted at by this part of the error message:
ImportError: dlopen(/.../cv2/cv2.cpython-37m-darwin.so, 2): Symbol not found: _clock_gettime
Referenced from: /...python3.7/site-packages/cv2/.dylibs/libavutil.56.22.100.dylib (which was built for Mac OS X 10.12)
Installing OpenCV requires ffmpeg. If you installed it via homebrew, it's listed as a dependency.
$ brew info opencv
...
==> Dependencies
Build: cmake ✓, pkg-config ✓
Required: eigen ✓, ffmpeg ✓, glog ✓, ...
Installing ffmpeg will include the libavutil library, which can be checked by downloading pre-built shared libraries or by Homebrew:
$ brew list ffmpeg | grep libavutil.*dylib
/usr/local/Cellar/ffmpeg/4.1.4_1/lib/libavutil.56.22.100.dylib
/usr/local/Cellar/ffmpeg/4.1.4_1/lib/libavutil.56.dylib
/usr/local/Cellar/ffmpeg/4.1.4_1/lib/libavutil.dylib
Now, your problem is that the libavutil (and ffmpeg) on your system is not backwards-compatible with your Mac 10.10. It was built targeting a newer Mac 10.12, which seems to have introduced changes to the clock_gettime API, causing the "Symbol not found" error. This has also been reported to the opencv-python issues:
This is not related to OpenCV. The error comes from libavutil
(=FFmpeg) which is installed via homebrew. The error is related to
binary backward compatibility (apparently Apple has changed the
libsystem interface). I'm not too familiar with Apples ecosystem but
building FFmpeg against earlier OS version might fix the issue if the
older symbols are present also in the latest OS versions. Full
backward compatibility on macOS might be impossible to achieve.
I was just bitten by this issue the hard way deep in nested
dependencies; FFmpeg targets 10.12 but I'm on 10.11. Hoping for a
fixed release soon.
Note that while downgrading Xcode may work too, the proper way to
target an earlier version of macOS is to add e.g.
-mmacosx-version-min=10.11 or -mmacosx-version-min=10.6 to CFLAGS/CXXFLAGS/LDFLAGS; this will tune headers, compiler and linker
to produce a binary that is compatible with at least that version of
macOS.
The only solution it seems, is to install an older version of ffmpeg (with libavutil) that is compatible with your Mac 10.10, and then tell OpenCV to link to that older version. You'll probably need to also build OpenCV from source (see Configure and Build OpenCV to Custom FFMPEG Install).
You can also try checking this post over at SuperUser:
Which ffmpeg package I should download for macOS?
Try installing the older ffmpeg#2.8 from Homebrew (though I'm not sure if that's going to work, I don't have a Mac 10.10 to test it on).
Try downloading pre-built static/shared builds from ffmpeg.org.
Try building it from source (see CompilationGuide/macOS)

AttributeError: module 'cv2.cv2' has no attribute 'createLBPHFaceRecognizer' in python 3.6.4 and opencv 3.4

I used different types of things and I need this to work in 3.6 Python. i also try
roc = cv2.face.LBPHFaceRecognizer_create() but getting the same error but this time with face module. Need help.
The same code is working in python 2.7.13, opencv 2.4.10.
How to make it work in python 3.6 and opencv 3.4.
I am working in a windows environment.
You likely have the opencv-python package installed instead of the opencv-contrib-python package. A lot of the proprietary algorithms were removed from the main OpenCV repository when OpenCV came out and put in the contrib repository.
Try switching versions.

Can't import cx_oracle in python3 on debian 7.11

I'm having trouble importing cx_Oracle into python3 on debian 7.11. I know it's old-stable, but I am restricted to this version until we migrate some services in production to servers with newer debian. The error I'm getting follows:
ImportError: /usr/local/lib/python3.2/dist-packages/cx_Oracle.cpython-32mu.so: undefined symbol: PyUnicode_GET_LENGTH
Python 3 was installed from official wheezy repos, no third parties. cx_oracle was installed using pip-3.2. Please point me in right direction.
It sounds like you are trying to use a newer version of cx_Oracle with an old version of Python. You'll want to try a newer version of Python (which you'll have to download and compile yourself) or you'll want to try an older version of cx_Oracle that still had support for Python 3.2.

Cannot install NumPy from a wheel format

I am trying to install NumPy from a wheel (.whl) file. I get the error:
numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
Details:
Windows 8.1 pro x64, elevated command prompt
Python 3.4.2
Package NumPy from Gohlke's site
File numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl copied in the pip.exe folder
The log file shows:
d:\Program Files\WinPython-64bit-3.4.2.4\python-3.4.2.amd64\Scripts\pip run on 01/23/15 11:55:21
numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
Exception information:
Traceback (most recent call last):
File "D:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "D:\Python34\lib\site-packages\pip\commands\install.py", line 257, in run
InstallRequirement.from_line(name, None))
File "D:\Python34\lib\site-packages\pip\req.py", line 167, in from_line
raise UnsupportedWheel("%s is not a supported wheel on this platform." % wheel.filename)
pip.exceptions.UnsupportedWheel: numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
What is wrong?
Short answer: rename the file to numpy-1.9.1%2Bmkl-cp34-none-win32.whl to install it.
You can check what tags your pip tool accepts for installation by running:
import pip; print(pip.pep425tags.get_supported())
In this case pip is incorrectly detecting your operating system to be 32-bits and the file you're trying to install was win_amd64 in its filename.
If you rename the file to numpy-1.9.1%2Bmkl-cp34-none-win32.whl (which now contains the tags that are considered supported) then you can install the package. It's a trick because the file is still built for 64-bits but this allows you to install the package as intended.
After several tests I think the problem is "win32" or "amd64" itself. I tried replacing those two with "any" and it worked.
In my case, the workaround to install gohlke packages on Python (3.4.4 (AMD64)) was to change the "cp34m" part rather than the "win*" parts in previous answers:
python -c "import pip; print(pip.pep425tags.get_supported())":
[('cp34', 'none', 'win_amd64'), ('py3', 'none', 'win_amd64'),
('cp34', 'none', 'any'), ...
ls -ld *:
matplotlib-2.0.0b3-cp34-cp34m-win_amd64.whl
numpy-1.11.1+mkl-cp34-cp34m-win_amd64.whl
pandas-0.18.1-cp34-cp34m-win_amd64.whl
Change the above names to:
matplotlib-2.0.0b3-cp34-none-win_amd64.whl
numpy-1.11.1+mkl-cp34-none-win_amd64.whl
pandas-0.18.1-cp34-none-win_amd64.whl
For example, pip install matplotlib-2.0.0b3-cp34-none-win_amd64.whl
Processing ...
...Successfully installed matplotlib-2.0.0b3
To add to the list of other possible solutions, I had to upgrade pip itself. The latest binary from Gholke's site had the "cp27m" tag, which didn't show up when I checked the pip tags using:
import pip; print(pip.pep425tags.get_supported())
After I upgraded pip, the wheel didn't work, but just doing a regular pip install numpy worked.
If you have, say, Python 3.4 installed, make sure to install the -cp34- version of the wheel and not -cp35-.
The current WinPython package manager need a two-characters fix to accept to recognize the new NumPy + mkl 'wheel'.
https://github.com/stonebig/winpython/commit/5e13230609a2e9f4d66d98c3776207ce4b4dd050
As a workaround, uninstall the NumPy package:
pip uninstall numpy
Then install it again from cache:
pip install numpy
I had the same problem with several packages after upgrading from 3.4.1 to 3.4.2.
Navigate to the directory where your 'pip.py' sits and then type following on the Windows command line:
..\python.exe pip.py install name_of_package.whl
This should work.
I had the same problem and tried to work it out with the suggested solutions.
I changed win64 to win32 and it didn't work either. But then I changed the name to original and this time it worked! The only extra thing I did was to go offline. That's so strange.
This has nothing to do with your operating system. Uninstall Python 32-bit and install Python 64-bit rather or alternatively find a 32-bit wheel file.

Resources