unable to install opencv in anaconda under python 3.7 version - opencv

conda install -c conda-forge opencv
Collecting package metadata (repodata.json): done
Solving environment: failed
Initial quick solve with frozen env failed. Unfreezing env and trying again.
Solving environment: failed
UnsatisfiableError: The following specifications were found to be incompatible with each other:
Package mkl-service conflicts for:
patsy -> scipy -> mkl-service[version='>=2,<3.0a0']
statsmodels -> patsy[version='>=0.4.0'] -> scipy -> mkl-service[version='>=2,<3.0a0']
scikit-image -> scipy[version='>=0.17,>=0.9'] -> mkl-service[version='>=2,<3.0a0']
scipy -> mkl-service[version='>=2,<3.0a0']
scikit-learn -> scipy -> mkl-service[version='>=2,<3.0a0']
mkl-service
seaborn -> statsmodels[version='>=0.5.0'] -> patsy[version='>=0.4.0'] -> scipy -> mkl-service[version='>=2,<3.0a0']
Package importlib_metadata conflicts for:
importlib_metadata
path.py -> importlib_metadata[version='>=0.5']
anaconda==2019.03=py37_0 -> path.py==11.5.0=py37_0 -> importlib_metadata[version='>=0.5']

I had the same issue and found this post usefull, specially the comment by merv.
Basically, there seems to be some incompatibilities between the configuration needed for the default packages of anaconda and the one for the opencv package.
In order to solve the problem you need to created a new enviroment for conda. This enviroment will contain the opencv package with the proper configuration without afecting other packages.
conda create --name env_opencv -c conda-forge opencv
This will create the "env" and install opencv in it with the configuration required by the package.
Then activate the enviroment.
conda activate env_opencv
More info about the enviroments on conda can be found here

Related

opencv import error (libopencv_dnn.so.4.5 undefined symbol)

I'd like to utilize my Movidius Neural Compute Stick 1 (NCS1) to learn deep learning.
However, when I run a sample code, the following import error occurs:
python3 emotion.py -i sample.jpg -o result.jpg
Traceback (most recent call last):
File "emotion.py", line 1, in <module>
import cv2
File "/opt/intel/openvino/python/python3/cv2/__init__.py", line 129, in <module>
bootstrap()
File "/opt/intel/openvino/python/python3/cv2/__init__.py", line 112, in bootstrap
import cv2
ImportError: /opt/intel/openvino/opencv/lib/libopencv_dnn.so.4.5:
undefined symbol: _ZN15InferenceEngine5TBlobIhSt9enable_ifILb1EvEED1Ev
I'm using a Raspberry Pi 3B.
The OS is Raspberry Pi OS 32-bit (Legacy) Buster because Bullseye doesn't support NCS1.
OpenVINO Version is l_openvino_toolkit_runtime_raspbian_p_2020.3.194.tgz,
which is the last version that supports NCS1.
Here's how to reproduce.
I installed Raspberry Pi OS 32-bit (Legacy) Buster onto the microSD.
After some simple initial settings, I typed these commands to install the OpenVINO toolkit:
sudo mkdir -p /opt/intel/openvino
mkdir ~/download
cd ~/download
wget https://storage.openvinotoolkit.org/repositories/openvino/packages/2020.3/l_openvino_toolkit_runtime_raspbian_p_2020.3.194.tgz
sudo tar -xf l_openvino_toolkit_runtime_raspbian_p_2020.3.194.tgz --strip 1 -C /opt/intel/openvino
echo "source /opt/intel/openvino/bin/setupvars.sh" >> ~/.bashrc
source /opt/intel/openvino/bin/setupvars.sh
sudo usermod -a -G users "$(whoami)"
sh /opt/intel/openvino/install_dependencies/install_NCS_udev_rules.sh
In order to set up the OpenCV environment, I typed:
sudo apt update
sudo apt install -y python3-pip
sudo apt install -y libopencv-dev
sudo apt install -y python3-numpy
pip3 install pillow
That's it.
Then, I downloaded necessary images and codes, and ran emotion.py.
The whole contents of emotion.py doesn't matter here because only the first line gives me the error.
more -10 emotion.py
import cv2
import numpy as np
from PIL import ImageFont, ImageDraw, Image
import argparse
import sys
from openvino.inference_engine import IECore
frame_png = cv2.imread("frame_main.png", cv2.IMREAD_UNCHANGED)
face_png = cv2.imread("frame_face.png", cv2.IMREAD_UNCHANGED)
gender_png = cv2.imread("frame_gender.png", cv2.IMREAD_UNCHANGED)
Addtional Info:
pi#raspberrypi:~ $ python -VV
Python 2.7.16
pi#raspberrypi:~ $ python3 -VV
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0]
Also, I tried to use berry-conda to do a similar thing with this answer.
But, it failed because the package libprotobuf is missing:
(After berry-conda installation)
pi#raspberrypi:/tmp $ which python
/home/pi/berryconda3/bin/python
pi#raspberrypi:/tmp $ which conda
/home/pi/berryconda3/bin/conda
pi#raspberrypi:/tmp $ python --version
Python 3.6.1
pi#raspberrypi:/tmp $ conda install -c defaults libprotobuf protobuf
Fetching package metadata .....
PackageNotFoundError: Package missing in current linux-armv7l channels:
- libprotobuf
This berry-conda installation completely changed my previous environment above.
I don't know if I should keep using berry-conda
or re-install Raspberry Pi OS 32-bit (Legacy) Buster again to do it from scratch.
Any suggestions would be greatly appreciated.
The error message is indicating that there is an issue with an undefined symbol in the libopencv_dnn.so.4.5 library, which suggests that there may be a compatibility issue between OpenVINO and the version of OpenCV installed on your system.
You could try reinstalling OpenVINO and making sure that it is properly configured with your system's version of OpenCV. You could also try updating or reinstalling OpenCV.

installation of OpenCV(cv2) in anaconda3 environment on Ubuntu 20.04 python 3.9.13.final.0

I've been trying to install cv2 on my machine (linux-Ubuntu20.04) with environment manager conda
my python and conda information is pasted below
Conda info:
active environment : base
active env location : /home/anonymous/anaconda3
shell level : 1
user config file : /home/anonymous/.condarc
populated config files : /home/anonymous/.condarc
conda version : 22.9.0
conda-build version : 3.22.0
python version : 3.9.13.final.0
virtual packages : __linux=5.15.0=0
__glibc=2.31=0
__unix=0=0
__archspec=1=x86_64
base environment : /home/anonymous/anaconda3 (writable)
conda av data dir : /home/anonymous/anaconda3/etc/conda
conda av metadata url : None
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /home/anonymous/anaconda3/pkgs
/home/anonymous/.conda/pkgs
envs directories : /home/anonymous/anaconda3/envs
/home/anonymous/.conda/envs
platform : linux-64
user-agent : conda/22.9.0 requests/2.28.1 CPython/3.9.13 Linux/5.15.0-52-generic ubuntu/20.04.5 glibc/2.31
UID:GID : 1000:1000
netrc file : None
offline mode : False
# conda environments:
#
base * /home/anonymous/anaconda3
sys.version: 3.9.13 (main, Oct 13 2022, 21:15:33)
[G...
sys.prefix: /home/anonymous/anaconda3
sys.executable: /home/anonymous/anaconda3/bin/python
conda location: /home/anonymous/anaconda3/lib/python3.9/site-packages/conda
conda-build: /home/anonymous/anaconda3/bin/conda-build
conda-content-trust: /home/anonymous/anaconda3/bin/conda-content-trust
conda-convert: /home/anonymous/anaconda3/bin/conda-convert
conda-debug: /home/anonymous/anaconda3/bin/conda-debug
conda-develop: /home/anonymous/anaconda3/bin/conda-develop
conda-env: /home/anonymous/anaconda3/bin/conda-env
conda-index: /home/anonymous/anaconda3/bin/conda-index
conda-inspect: /home/anonymous/anaconda3/bin/conda-inspect
conda-metapackage: /home/anonymous/anaconda3/bin/conda-metapackage
conda-pack: /home/anonymous/anaconda3/bin/conda-pack
conda-render: /home/anonymous/anaconda3/bin/conda-render
conda-repo: /home/anonymous/anaconda3/bin/conda-repo
conda-server: /home/anonymous/anaconda3/bin/conda-server
conda-skeleton: /home/anonymous/anaconda3/bin/conda-skeleton
conda-token: /home/anonymous/anaconda3/bin/conda-token
conda-verify: /home/anonymous/anaconda3/bin/conda-verify
user site dirs:
CIO_TEST: <not set>
CONDA_DEFAULT_ENV: base
CONDA_EXE: /home/anonymous/anaconda3/bin/conda
CONDA_PREFIX: /home/anonymous/anaconda3
CONDA_PROMPT_MODIFIER: (base)
CONDA_PYTHON_EXE: /home/anonymous/anaconda3/bin/python
CONDA_ROOT: /home/anonymous/anaconda3
I've been trying several days installing opencv(cv2) on conda base environment with this line of code:
conda install -c conda-forge opencv
conda install -c "conda-forge/label/broken" opencv
conda install -c "conda-forge/label/cf201901" opencv
conda install -c "conda-forge/label/cf202003" opencv
conda install -c "conda-forge/label/gcc7" opencv
i had tried
conda install -c menpo opencv
to but it didn't work for me.
for last try i run this code:
conda install --channel https://conda.anaconda.org/menpo opencv3
and i received this massage:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: |
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- opencv3 -> python[version='2.7.*|3.4.*|3.5.*|3.6.*']
Your python: python=3.9
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
The following specifications were found to be incompatible with your system:
- feature:/linux-64::__glibc==2.31=0
- feature:|#/linux-64::__glibc==2.31=0
Your installed version is: 2.31
Any help is appreciated.

conda python 3.7 opencv import error libgnutls.so.30: undefined symbol: mpn_add_1, version HOGWEED_4

I am facing problem while getting opencv to work with python 3.7 in Conda on Ubuntu 20.04.
I get the following error when I try to import cv2 in python:
$ python
Python 3.7.8 | packaged by conda-forge | (default, Jul 23 2020, 03:54:19)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/swagat/anaconda3/envs/tf2py37/lib/python3.7/site-packages/../../././libgnutls.so.30: undefined symbol: mpn_add_1, version HOGWEED_4
my Conda configuration looks something like this:
active environment : tf2py37
active env location : /home/swagat/anaconda3/envs/tf2py37
shell level : 2
user config file : /home/swagat/.condarc
populated config files :
conda version : 4.8.5
conda-build version : 3.18.9
python version : 3.7.4.final.0
virtual packages : __cuda=10.1
__glibc=2.31
I installed opencv from the conda-forge channel using the following command:
$ conda install -c conda-forge opencv
I can see that opencv is installed on my system:
$ conda list opencv
# packages in environment at /home/swagat/anaconda3/envs/tf2py37:
#
# Name Version Build Channel
libopencv 4.5.0 py37_2 conda-forge
opencv 4.5.0 py37_2 conda-forge
py-opencv 4.5.0 py37hc6149b9_2 conda-forge
I also checked if gnutls is installed:
$ conda list gnutls
# packages in environment at /home/swagat/anaconda3/envs/tf2py37:
#
# Name Version Build Channel
gnutls 3.6.13 h79a8f9a_0 conda-forge
What else I can try to solve this problem? I am kind of stuck here. Any help will be appreciated. Thanks.
It seems that conda version of the opencv is broken.
My solution is:
remove your conda opencv and install the native one:
conda remove opencv
python -m pip install opencv-python # Execute this with your conda env activated

Alpine Linux How to install x86 packages on x86_64 architecture

I am trying to install 32-bit packages on official alpine docker images but whenever I do apk add libcurl for example it install 64-bit version of libcurl whereas I want to install 32-bit package.
Any thoughts how to do the same on Alpine Linux 3.7?
Actually, only one file defines which packages take from alpine repos. It is /etc/apk/arch:
# cat /etc/apk/arch
x86_64
Its value shows which packages we should take from our alpine repos:
# cat /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/v3.7/main
http://dl-cdn.alpinelinux.org/alpine/v3.7/community
So, we can make a trick here. We can "switch" alpine to get x86 packages from the repos:
/ # echo "x86" > /etc/apk/arch
/ # apk add --no-cache libcurl
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86/APKINDEX.tar.gz
(1/12) Replacing musl (1.1.18-r2 -> 1.1.18-r2)
(2/12) Replacing busybox (1.27.2-r8 -> 1.27.2-r8)
Executing busybox-1.27.2-r8.post-upgrade
(3/12) Replacing alpine-baselayout (3.0.5-r2 -> 3.0.5-r2)
Executing alpine-baselayout-3.0.5-r2.pre-upgrade
Executing alpine-baselayout-3.0.5-r2.post-upgrade
(4/12) Replacing libressl2.6-libcrypto (2.6.3-r0 -> 2.6.3-r0)
(5/12) Replacing libressl2.6-libssl (2.6.3-r0 -> 2.6.3-r0)
(6/12) Replacing zlib (1.2.11-r1 -> 1.2.11-r1)
(7/12) Replacing apk-tools (2.8.2-r0 -> 2.8.2-r0)
(8/12) Replacing scanelf (1.2.2-r1 -> 1.2.2-r1)
(9/12) Replacing musl-utils (1.1.18-r2 -> 1.1.18-r2)
(10/12) Installing ca-certificates (20171114-r0)
(11/12) Installing libssh2 (1.8.0-r2)
(12/12) Installing libcurl (7.57.0-r0)
Executing busybox-1.27.2-r8.trigger
Executing ca-certificates-20171114-r0.trigger
OK: 5 MiB in 14 packages
Since you're using Docker, why not use the 32-bit alpine image?
$ docker run --rm -it i386/alpine
/ # apk add --no-cache libcurl
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86/APKINDEX.tar.gz
...
More info: Architectures other than amd64?

Installing opencv for python3

Has anyone tried to install opencv for python3?. As stated here http://opencv.willowgarage.com/wiki/InstallGuide its support status is unknown. So I want to try it:
I have downloaded the sources for OpenCV-2.3.1. But cmake reports.
-- Python interpreter: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 -B (ver
3.2)
-- Python numpy: NO (Python wrappers will not be generated)
I do have numpy (version 1.6.0) installed in python3 but cmake does not find it. I am using Mac OSX 10.6 Any ideas?
Update
I just saw one more thing of the cmake output that might be helpful
-- Found PythonInterp: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 (found
version "3.2")
-- Found PythonLibs: /usr/lib/libpython2.6.dylib File "", line 1
from distutils.sysconfig import *; print get_python_lib()
^
SyntaxError: invalid syntax File "", line 1
import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print
numpy.distutils.misc_util.get_numpy_include_dirs()[0]
^
SyntaxError: invalid syntax File "", line 1
import sphinx; print sphinx.__version__
^ SyntaxError: invalid syntax
Notice that it found 3.2 but then libpython2.6 ??
Any ideas?
At the moment OpenCV supports Python 2.x only. OpenCV (including OpenCV 2.4) does not compiles with Python 3.x.
Python3 support is already in wishlist for future versions of OpenCV. But currently there are no activities in this direction and you are welcome to create and contribute a patch resolving the compatibility issues.
Use the pip application.
On ubuntu:
sudo apt install python3-pip
and so, on command line:
pip3 install --upgrade pip
pip3 install opencv-python
I got the thing to at least build and install. It can load the cv2 module just fine. Haven't tested too much though.
Details:
https://stackoverflow.com/a/21212023/3075814

Resources