首页 > 解决方案 > Opencv 2.4.13 需要 python 2.7,但是 Monoocular Total Capture repo 需要 python 3.5

问题描述

我正在尝试使用这个 repo:

https://github.com/CMU-Perceptual-Computing-Lab/MonocularTotalCapture

它需要“OpenCV 2.4.13(使用 CUDA 9.0、CUDNN 7.0 从源代码编译)”,所以我正在尝试使用 conda 安装它。我的系统上的默认 python 安装是:

(base) root@ziom-Z87-HD3:/home/ziom# python
Python 2.7.16 |Anaconda, Inc.| (default, Sep 24 2019, 21:51:30) 
[GCC 7.3.0] on linux2

但是 repo 需要 python 3.5,因此我用这个命令切换到它:

alias python='/usr/bin/python3.5'

它似乎奏效了。

(base) root@ziom-Z87-HD3:/home/ziom# python
Python 3.5.2 (default, Oct  8 2019, 13:06:37) 
[GCC 5.4.0 20160609] on linux

现在,它需要安装 python 3.5 和 OpenCV 2.4.13,所以我给出这个命令:

conda create -n ziomario pip python=3.5
conda activate ziomario

此时我应该安装 OpenCV 2.4.13 并给出以下命令:

conda install -c conda-forge opencv=2.4.13

但它不起作用,因为:

(ziomario) root@ziom-Z87-HD3:/home/ziom# conda install -c conda-forge opencv=2.4.13
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.
Examining @/linux-64::__glibc==2.23=0:  25%|██▌       | 1/4 [00:00<00:00, 6026.3Examining python=3.5:  50%|█████     | 2/4 [00:00<00:00, 7351.98it/s]           Examining conflict for python opencv:  25%|██▌       | 1/4 [00:00<00:00, 10979.8                                                                                failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - opencv=2.4.13 -> python=2.7

Your python: python=3.5

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 CUDA driver:

  - feature:/linux-64::__cuda==9.0=0

Your installed CUDA driver is: 9.0

Opencv=2.4.13 需要 python=2.7,但 repo 需要 python 3.5。我不知道该怎么办。

标签: pythonlinuxopencvtensorflowanaconda

解决方案


为此,您可能需要使用“pyenv”

我发现该网站非常有用:https ://realpython.com/intro-to-pyenv/

假设您使用的是 Ubuntu 或 Debian 系统,我将编写步骤摘要。

首先,如果您还没有下载依赖项,请先下载:

$ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl

然后你使用 pyenv-installer:

$ curl https://pyenv.run | bash

这将安装 pyenv 以及一些有用的插件:

  1. pyenv:实际的 pyenv 应用程序
  2. pyenv-virtualenv:pyenv 和虚拟环境的插件
  3. pyenv-update:用于更新 pyenv 的插件
  4. pyenv-doctor:用于验证是否安装了 pyenv 和构建依赖项的插件
  5. pyenv-which-ext:自动查找系统命令的插件

在运行结束时,您应该会看到如下内容:

WARNING: seems you still have not added 'pyenv' to the load path.

# Load pyenv automatically by adding
# the following to ~/.bashrc:

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

The output will be based on your shell. But you should follow the instructions to add pyenv to your path and to initialize pyenv/pyenv-virtualenv auto completion. Once you’ve done this, you need to reload your shell:
$ exec "$SHELL" # Or just restart your terminal

然后,您可以使用该命令安装 python 版本:

$ pyenv install -v 3.5

还有更多...(访问网站)


推荐阅读