How to Install Python Opencv Through Conda

Installing OpenCV with Conda and Spyder

The answer for this issue is updating Anaconda to the newest version:

conda update -n base -c defaults conda

then you can install opencv normally using:

conda install -c conda-forge opencv

Install Opencv from source to conda environment

By default it will install to your system Python path which you can see by entering:

which python

in the terminal. In your cmake commands (the above list you posted) you need to tell it which python executable path you want to build to. At the moment your build is pointing to the above default Python location, and now you want to point it to your Conda Python path. So for example, my base path for my Python environment in Anaconda is:

/home/robert/anaconda3/

You can get a list of your Anaconda environments and their location by entering this in the terminal:

conda env list

To do this, you'll need to update the cmake commands to tell it where the Python path which you want to build to is located. I've used this post before to help me correctly specify the Python executable build path, and it has worked for me when specifying the Python path for a venv.

For example, if I wanted to install to one of my Anaconda environments I would do something like this in my cmake:

-D PYTHON_DEFAULT_EXECUTABLE=$(/home/robert/anaconda3/envs/venv_openvcv/python3)

When you build cmake, scroll through the output and pay particular attention to the line which says something like:

Python (for build): /home/robert/anaconda3/envs/venv_openvcv/python3

This is your way of confirming if it is about to build opencv to the correct Python executable (the Anaconda one you have specified).

Edit: Additionally here is a tutorial which outlines in detail the steps to compile OpenCV for an Anaconda environment - Installing OpenCV for Conda Virtual Environments

Installing OpenCV From Conda Environment YML File

You have fixed it yourself by moving the requirements to the pip section, which results in an installation from Pypi. I just wanted to add explanation why your original attempt did not work and suggestions in case you want to strictly stick to using conda. Note that for both tensorflow and opencv, the packages provided on conda-forge are not maintained by the respective developers, often resulting in them lacking behind in versions.

The python bindings for openCV are called py-opencv on conda forge and have different version strings, so you would need to put py-opencv==4.6.0 in your yml

tensorflow on conda-forge goes only up to 2.8.1. So when strictly sticking to conda, you would need to downgrade the version

You can always check available versions for packages by using conda search -c <channel> <package-name> from your terminal

Opencv not installing on Anaconda prompt

Please note that to import cv2, the library/package to install is called opencv-python.

From Jupyter notebook, you can try !pip install opencv-python

If you're using anaconda, you can try conda install -c conda-forge opencv-python

How to install opencv in anaconda on windows

We had the same issue described in the other answer with 3.7, however the command that worked is conda create --name py3 python=3.6 following by activate py3 and it should work for you.



Related Topics



Leave a reply



Submit