pip依赖解析器问题 – singularity容器 – cuda和torch

huangapple go评论65阅读模式
英文:

pip dependency resolver issue - singularity container - cuda and torch

问题

我想使用以下定义文件为一个Python库构建一个 singularity 容器:

Bootstrap: docker
From: nvcr.io/nvidia/pytorch:21.06-py3

%post
        export DEBIAN_FRONTEND=noninteractive

        apt-get update
        apt-get -y install pip wget git vim
        pip install opencv-python-headless

        pip install 'git+https://github.com/facebookresearch/fvcore'

        cd /opt
        git clone https://github.com/facebookresearch/detectron2.git detectron2_repo
        cd detectron2_repo
        pip install .

在构建容器时,在 pip install . 之后,我遇到以下错误:

Successfully built detectron2 fvcore antlr4-python3-runtime pycocotools fairscale
Installing collected packages: zipp, numpy, antlr4-python3-runtime, tomli, platformdirs, pathspec, omegaconf, mypy-extensions, iopath, importlib-resources, huggingface-hub, click, timm, pycocotools, hydra-core, fvcore, fairscale, cloudpickle, black, detectron2
  Attempting uninstall: numpy
    Found existing installation: numpy 1.20.3
    Uninstalling numpy-1.20.3:
      Successfully uninstalled numpy-1.20.3
  Attempting uninstall: iopath
    Found existing installation: iopath 0.1.10
    Uninstalling iopath-0.1.10:
      Successfully uninstalled iopath-0.1.10
  Attempting uninstall: click
    Found existing installation: click 7.1.2
    Uninstalling click-7.1.2:
      Successfully uninstalled click-7.1.2
  Attempting uninstall: pycocotools
    Found existing installation: pycocotools 2.0+nv0.5.1
    Uninstalling pycocotools-2.0+nv0.5.1:
      Successfully uninstalled pycocotools-2.0+nv0.5.1
  Attempting uninstall: fvcore
    Found existing installation: fvcore 0.1.6
    Uninstalling fvcore-0.1.6:
      Successfully uninstalled fvcore-0.1.6
ERROR: pips dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
typer 0.3.2 requires click<7.2.0,>=7.1.1, but you have click 8.1.3 which is incompatible.
scipy 1.6.3 requires numpy<1.23.0,>=1.16.5, but you have numpy 1.24.2 which is incompatible.

因此,它首先卸载了 click 7.1.2numpy 1.20.3 这两个兼容版本,然后安装了其他不兼容的版本,并抱怨它们不兼容。为什么会发生这种情况?如何解决?

我尝试过的方法:

  1. setup.py 文件中添加额外的行,以指定正确的安装版本。但仍然出现相同的问题。
  2. 从 NVIDIA NGC 的另一个版本的 pytorch 开始。对于其他软件包,它产生相同的错误。
  3. 从没有安装 CUDA 的纯 Ubuntu 启动容器。我没有遇到任何错误,但我需要 CUDA 用于 GPU。
  4. 在定义文件的最后一行之前构建容器,然后运行容器,从容器内运行 pip install --user e .。这解决了错误,但我仍然需要使用容器安装软件包。
英文:

I want to build a singularity container for a python library using the following def file:

Bootstrap: docker
From: nvcr.io/nvidia/pytorch:21.06-py3

%post
        export DEBIAN_FRONTEND=noninteractive

        apt-get update
        apt-get -y install pip wget git vim
        pip install opencv-python-headless

        pip install 'git+https://github.com/facebookresearch/fvcore'

        cd /opt
        git clone https://github.com/facebookresearch/detectron2.git detectron2_repo
        cd detectron2_repo
        pip install .

While building the container, after the line pip install ., I get the following error:

Successfully built detectron2 fvcore antlr4-python3-runtime pycocotools fairscale
Installing collected packages: zipp, numpy, antlr4-python3-runtime, tomli, platformdirs, pathspec, omegaconf, mypy-extensions, iopath, importlib-resources, huggingface-hub, click, timm, pycocotools, hydra-core, fvcore, fairscale, cloudpickle, black, detectron2
  Attempting uninstall: numpy
    Found existing installation: numpy 1.20.3
    Uninstalling numpy-1.20.3:
      Successfully uninstalled numpy-1.20.3
  Attempting uninstall: iopath
    Found existing installation: iopath 0.1.10
    Uninstalling iopath-0.1.10:
      Successfully uninstalled iopath-0.1.10
  Attempting uninstall: click
    Found existing installation: click 7.1.2
    Uninstalling click-7.1.2:
      Successfully uninstalled click-7.1.2
  Attempting uninstall: pycocotools
    Found existing installation: pycocotools 2.0+nv0.5.1
    Uninstalling pycocotools-2.0+nv0.5.1:
      Successfully uninstalled pycocotools-2.0+nv0.5.1
  Attempting uninstall: fvcore
    Found existing installation: fvcore 0.1.6
    Uninstalling fvcore-0.1.6:
      Successfully uninstalled fvcore-0.1.6
ERROR: pips dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
typer 0.3.2 requires click<7.2.0,>=7.1.1, but you have click 8.1.3 which is incompatible.
scipy 1.6.3 requires numpy<1.23.0,>=1.16.5, but you have numpy 1.24.2 which is incompatible.

So, it first uninstalls click 7.1.2 and numpy 1.20.3 which are the compatible versions and then installs other versions of them which are not compatible, and complains that they are incompatible.
Why does this happen? and how to fix it?

what I tried:

  1. add extra lines to the setup.py file in order to specify the correct versions for installation. But it still does the same thing.
  2. start from another release of pytorch from nvidia ngc. It produces the same error for other packages.
  3. start the container from plain ubuntu without installing cuda. I do not get any error but I need cuda for the gpu.
  4. build the container without the last line in the def file, then run the container and from inside the container run pip install --user e . . This resolves the errors but I still need to install the package using the container.

答案1

得分: 1

我有两种方式解决了这个问题:

  1. 在容器内使用虚拟环境。然而,在这种情况下,需要在虚拟环境内重新安装 torch,这是没有意义的。
Bootstrap: docker
From: nvcr.io/nvidia/pytorch:21.06-py3
%post
        export DEBIAN_FRONTEND=noninteractive
        apt-get update
        apt-get -y install pip wget git vim  python3-venv
        python3 -m venv /opt/myenv
        . /opt/myenv/bin/activate # 在容器中使用 . 而不是 source 命令
        pip install tensorboard
        pip install opencv-python-headless
        pip install 'git+https://github.com/facebookresearch/fvcore'
        pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
        cd /opt
        git clone https://github.com/facebookresearch/detectron2.git
        cd detectron2_repo
        pip install .
  1. 或者基于 cuda docker 镜像构建容器,而不是基于 torch docker 镜像,然后安装 torch。
Bootstrap: docker
From: nvcr.io/nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04
%post
        export DEBIAN_FRONTEND=noninteractive
        apt-get update
        apt-get -y install pip wget git vim  python3-venv
        pip install opencv-python-headless
        pip install tensorboard
        pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
        pip install 'git+https://github.com/facebookresearch/fvcore'
        cd /opt
        git clone https://github.com/facebookresearch/detectron2.git
        cd detectron2_repo
        pip install .

显然,第二种方式更为合理。

英文:

I solved the problem in two ways:

  1. either use a virtual environment inside the container. However in this case, one needs to re-install torch inside the virtual environment which is nonsense.
Bootstrap: docker
From: nvcr.io/nvidia/pytorch:21.06-py3
%post
        export DEBIAN_FRONTEND=noninteractive
        apt-get update
        apt-get -y install pip wget git vim  python3-venv
        python3 -m venv /opt/myenv
        . /opt/myenv/bin/activate # use . instead of source command in container
        pip install tensorboard
        pip install opencv-python-headless
        pip install 'git+https://github.com/facebookresearch/fvcore'
        pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
        cd /opt
        git clone https://github.com/facebookresearch/detectron2.git
        cd detectron2_repo
        pip install .
  1. or build the container based on a cuda docker image instead of a torch docker image, and then install torch.
Bootstrap: docker
From: nvcr.io/nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04
%post
        export DEBIAN_FRONTEND=noninteractive
        apt-get update
        apt-get -y install pip wget git vim  python3-venv
        pip install opencv-python-headless
        pip install tensorboard
        pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
        pip install 'git+https://github.com/facebookresearch/fvcore'
        cd /opt
        git clone https://github.com/facebookresearch/detectron2.git
        cd detectron2_repo
        pip install .

Obviously, the 2nd way is more reasonable.

huangapple
  • 本文由 发表于 2023年3月15日 21:11:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745206.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定