Conda で OpenCV をインストールする

1.condaスイッチ仮想環境

activate 虚拟环境名称

リマインダー: 仮想環境のリストをクエリする

conda env list

 

2.conda viewのインストールソース

conda config --show-sources

私のローカルインストールソースは次のとおりです:  /anaconda/pkgs/free/ のインデックス | 清華大学オープンソース ソフトウェア ミラー ステーション | 清華大学オープンソース ミラー

conda のデフォルトのインストール ソースを変更するには、次のコマンドを実行してください。

# 安装清华安装源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

# 移除conda 默认安装源
conda config --remove channels defaults

3. Condaクエリopencvバージョン

conda search opencv

実行効果:

 

4.opencvをインストールする 

リマインダー: opencv をインストールし、Python の最小バージョン要件とサポートされている最も高い Python バージョンに注意してください。

opencv3 のインストール:

(python310) C:\Windows\System32>conda install opencv=3.4.2
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
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:

  - opencv=3.4.2 -> python[version='>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0']

Your python: python=3.10

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.

結論: OpenCV 3.4.2 のインストールは Python ではサポートされていません。

 opencv4 のインストール:

(python310) C:\Windows\System32>conda install opencv=4.5.5
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: |
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - defaults/win-64::matplotlib==3.7.1=py310haa95532_1
done

## Package Plan ##

  environment location: D:\anaconda3\envs\python310

  added / updated specs:
    - opencv=4.5.5


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    eigen-3.3.7                |       h59b6b97_1         831 KB  defaults
    hdf5-1.8.15.1              |                2         1.4 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    libprotobuf-3.20.3         |       h23ce68f_0         2.2 MB  defaults
    numpy-1.21.5               |  py310h6d2d95c_3          25 KB  defaults
    numpy-base-1.21.5          |  py310h206c741_3         4.4 MB  defaults
    opencv-4.5.5               |  py310he826a15_4        24.5 MB  defaults
    ------------------------------------------------------------
                                           Total:        33.4 MB

The following NEW packages will be INSTALLED:

  eigen              pkgs/main/win-64::eigen-3.3.7-h59b6b97_1
  hdf5               anaconda/pkgs/free/win-64::hdf5-1.8.15.1-2
  libprotobuf        pkgs/main/win-64::libprotobuf-3.20.3-h23ce68f_0
  opencv             pkgs/main/win-64::opencv-4.5.5-py310he826a15_4
  pyqt               pkgs/main/win-64::pyqt-5.15.7-py310hd77b12b_0

The following packages will be DOWNGRADED:

  numpy                              1.23.5-py310h60c9a35_0 --> 1.21.5-py310h6d2d95c_3
  numpy-base                         1.23.5-py310h04254f7_0 --> 1.21.5-py310h206c741_3


Proceed ([y]/n)? y


Downloading and Extracting Packages

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

正常にインストールされました。 

5. opencv が正常にインストールされていることを確認します

(python310) C:\Windows\System32>python
Python 3.10.10 | packaged by Anaconda, Inc. | (main, Mar 21 2023, 18:39:17) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
4.5.5
>>>

opencv環境はあらかじめ用意されています。

Supongo que te gusta

Origin blog.csdn.net/zhouzhiwengang/article/details/130506184
Recomendado
Clasificación