- 遇到的坑
- 第二个坑
- 第三个坑
- 测试成果
安装opencv的时候遇到了各种问题。
首先是版本问题,conda可以用任意版本,但是opencv3需要python3.5 python3.6才可以,python3.7会提示版本不合适。
(courtDetetion) ubuntu@ubuntu-C246-WU4:~$ conda install --channel https://conda.anaconda.org/menpo opencv3 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.7 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.23=0 - feature:|@/linux-64::__glibc==2.23=0 Your installed version is: 2.23
这里提示python版本的问题,所以需要新建一个conda环境。
(courtDetetion) ubuntu@ubuntu-C246-WU4:~$ conda deactivate (courtDetetion) ubuntu@ubuntu-C246-WU4:~$ conda remove -n courtDetetion --all (courtDetetion) ubuntu@ubuntu-C246-WU4:~$ conda create -n courtDetection python=3.6 (courtDetetion) ubuntu@ubuntu-C246-WU4:~$ conda activate courtDetection (courtDetection) ubuntu@ubuntu-C246-WU4:~$
remove这一步看自己需要,如果你还有别的用处的话可以不删除,但我这里是专门为了场地识别建的环境,后面想用相同的名字,所以就删掉了。
第二个坑进入新的环境后,再次安装opencv3,但是提示MD5错误。这里不知道为啥,应该是下载的包的问题,因此我自己下载了对应的包,见下面:
(courtDetection) ubuntu@ubuntu-C246-WU4:~$ conda install --channel https://conda.anaconda.org/menpo opencv3 Collecting package metadata (repodata.json): done Solving environment: done ## Package Plan ## environment location: /home/ubuntu/anaconda3/envs/courtDetection added / updated specs: - opencv3 The following packages will be downloaded: package | build ---------------------------|----------------- mkl-service-2.3.0 | py36he8ac12f_0 56 KB mkl_fft-1.3.0 | py36h54f3939_0 185 KB mkl_random-1.1.1 | py36h0573a6f_0 382 KB numpy-1.19.2 | py36h54aff64_0 21 KB numpy-base-1.19.2 | py36hfa32c7d_0 5.2 MB opencv3-3.1.0 | py36_0 37.4 MB menpo ------------------------------------------------------------ Total: 43.2 MB The following NEW packages will be INSTALLED: blas pkgs/main/linux-64::blas-1.0-mkl intel-openmp pkgs/main/linux-64::intel-openmp-2021.4.0-h06a4308_3561 mkl pkgs/main/linux-64::mkl-2020.2-256 mkl-service pkgs/main/linux-64::mkl-service-2.3.0-py36he8ac12f_0 mkl_fft pkgs/main/linux-64::mkl_fft-1.3.0-py36h54f3939_0 mkl_random pkgs/main/linux-64::mkl_random-1.1.1-py36h0573a6f_0 numpy pkgs/main/linux-64::numpy-1.19.2-py36h54aff64_0 numpy-base pkgs/main/linux-64::numpy-base-1.19.2-py36hfa32c7d_0 opencv3 menpo/linux-64::opencv3-3.1.0-py36_0 six pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_0 Proceed ([y]/n)? y Downloading and Extracting Packages mkl_fft-1.3.0 | 185 KB | ##################################### | 100% numpy-base-1.19.2 | 5.2 MB | ##################################### | 100% mkl_random-1.1.1 | 382 KB | ##################################### | 100% mkl-service-2.3.0 | 56 KB | ##################################### | 100% opencv3-3.1.0 | 37.4 MB | | 0% numpy-1.19.2 | 21 KB | ##################################### | 100% ChecksumMismatchError: Conda detected a mismatch between the expected content and downloaded content for url 'https://conda.anaconda.org/menpo/linux-64/opencv3-3.1.0-py36_0.tar.bz2'. download saved to: /home/ubuntu/anaconda3/pkgs/opencv3-3.1.0-py36_0.tar.bz2 expected md5: cb5f5ec720aecaf40544672d2c1a3878 actual md5: 35977be7d3cb7e5cfb5ddb30ea175761
根据上面的提示,我们到https://anaconda.org/menpo/opencv3/files上下载对应的包,这里我根据自己的 *** 作环境选了linux-64/opencv3-3.1.0-py36_0.tar.bz2。下载之后,把这个包移动到对应的目录下,根据上面的报错信息,需要移动到"download saved to"对应的目录下:
(courtDetection) ubuntu@ubuntu-C246-WU4:~$ cd /home/ubuntu/anaconda3/pkgs/ (courtDetection) ubuntu@ubuntu-C246-WU4:~/anaconda3/pkgs$ mv ~/Download/opencv3-3.1.0-py36_0.tar.bz2 .
之后,安装这个包:
(courtDetection) ubuntu@ubuntu-C246-WU4:~/anaconda3/pkgs$ conda install opencv3-3.1.0-py36_0.tar.bz2
之后应该就结束了。
第三个坑如果这时候还有问题,可能是opencv3的一些依赖包没有安装,只要按照对应的提示信息安装即可。
如,可能numpy没安装,就
(courtDetection) ubuntu@ubuntu-C246-WU4:~/anaconda3/pkgs$ conda install -f numpy测试成果
成功的标志是import cv2无报错。如:
(courtDetection) ubuntu@ubuntu-C246-WU4:~/anaconda3/pkgs$ python Python 3.6.13 |Anaconda, Inc.| (default, Jun 4 2021, 14:25:59) [GCC 7.5.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> print(cv2.__version__) 3.1.0 >>> exit()
这样可以正确输出版本号,就没有问题了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)