安装mmcv时出现报错

root@autodl-container-c10245bd8d-ec01c20f:~/CGFormer-main# pip install mmcv
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Collecting mmcv
  Using cached http://mirrors.aliyun.com/pypi/packages/e9/a2/57a733e7e84985a8a0e3101dfb8170fc9db92435c16afad253069ae3f9df/mmcv-2.2.0.tar.gz (479 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      /tmp/pip-install-fegourma/mmcv_606fa99d541d49aab05070bc597c1f1f/setup.py:5: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
        from pkg_resources import DistributionNotFound, get_distribution, parse_version
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-fegourma/mmcv_606fa99d541d49aab05070bc597c1f1f/setup.py", line 19, in <module>
          from torch.utils.cpp_extension import BuildExtension
        File "/root/miniconda3/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 28, in <module>
          from pkg_resources import packaging  # type: ignore[attr-defined]
      ImportError: cannot import name 'packaging' from 'pkg_resources' (/root/miniconda3/lib/python3.10/site-packages/pkg_resources/__init__.py)
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

很大的可能是因为python版本和mmcv不兼容,此时可以参考下面的mmcv的官方安装文档

一般解决方案

pip install -U openmim
mim install mmcv
##有时安装成功之后会显示有些模块没有,是因为安装的是mmcv而不是mmcv-full
可以尝试安装mmcv-full解决
mim install mmcv-full

INSTALLATION

There are two versions of MMCV:

  • mmcv: comprehensive, with full features and various CUDA ops out of box. It takes longer time to build.

  • mmcv-lite: lite, without CUDA ops but all other features, similar to mmcv<1.0.0. It is useful when you do not need those CUDA ops.

警告

Do not install both versions in the same environment, otherwise you may encounter errors like ModuleNotFound. You need to uninstall one before installing the other. Installing the full version is highly recommended if CUDA is avaliable.

Install mmcv

Before installing mmcv, make sure that PyTorch has been successfully installed following the PyTorch official installation guide. This can be verified using the following command

python -c 'import torch;print(torch.__version__)'

If version information is output, then PyTorch is installed.

Install with mim (recommended)

mim is the package management tool for the OpenMMLab projects, which makes it easy to install mmcv

pip install -U openmim
mim install mmcv

If you find that the above installation command does not use a pre-built package ending with .whl but a source package ending with .tar.gz, you may not have a pre-build package corresponding to the PyTorch or CUDA or mmcv version, in which case you can build mmcv from source.

Installation log using pre-built packages


 

Installation log using source packages


 

To install a specific version of mmcv, for example, mmcv version 2.0.0, you can use the following command

mim install mmcv==2.0.0

注解

If you would like to use opencv-python-headless instead of opencv-python, e.g., in a minimum container environment or servers without GUI, you can first install it before installing MMCV to skip the installation of opencv-python.

Alternatively, if it takes too long to install a dependency library, you can specify the pypi source

mim install mmcv -i https://pypi.tuna.tsinghua.edu.cn/simple

You can run check_installation.py to check the installation of mmcv-full after running the installation commands.

Install with pip

Use the following command to check the version of CUDA and PyTorch

python -c 'import torch;print(torch.__version__);print(torch.version.cuda)'

Select the appropriate installation command depending on the type of system, CUDA version, PyTorch version, and MMCV version

LinuxWindowsmacOScuda 12.1cuda 11.8cuda 11.7cuda 11.6cuda 11.5cuda 11.3cuda 11.1cuda 11.0cuda 10.2cuda 10.1cuda 9.2cputorch 2.3.xtorch 2.2.xtorch 2.1.xmmcv 2.2.0

pip install mmcv==2.2.0 -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.3/index.html

If you do not find a corresponding version in the dropdown box above, you probably do not have a pre-built package corresponding to the PyTorch or CUDA or mmcv version, at which point you can build mmcv from source.

注解

mmcv is only compiled on PyTorch 1.x.0 because the compatibility usually holds between 1.x.0 and 1.x.1. If your PyTorch version is 1.x.1, you can install mmcv compiled with PyTorch 1.x.0 and it usually works well. For example, if your PyTorch version is 1.8.1, you can feel free to choose 1.8.x.

注解

If you would like to use opencv-python-headless instead of opencv-python, e.g., in a minimum container environment or servers without GUI, you can first install it before installing MMCV to skip the installation of opencv-python.

Alternatively, if it takes too long to install a dependency library, you can specify the pypi source

mim install mmcv -i https://pypi.tuna.tsinghua.edu.cn/simple

You can run check_inst安装allation.py to check the installation of mmcv after running the installation commands.

Using mmcv with Docker

Build with local repository

git clone https://github.com/open-mmlab/mmcv.git && cd mmcv
docker build -t mmcv -f docker/release/Dockerfile .

Or build with remote repository

docker build -t mmcv https://github.com/open-mmlab/mmcv.git#main:docker/release

The Dockerfile installs latest released version of mmcv-full by default, but you can specify mmcv versions to install expected versions.

docker image build -t mmcv -f docker/release/Dockerfile --build-arg MMCV=2.0.0 .

If you also want to use other versions of PyTorch and CUDA, you can also pass them when building docker images.

An example to build an image with PyTorch 1.11 and CUDA 11.3.

docker build -t mmcv -f docker/release/Dockerfile \
    --build-arg PYTORCH=1.11.0 \
    --build-arg CUDA=11.3 \
    --build-arg CUDNN=8 \
    --build-arg MMCV=2.0.0 .

More available versions of PyTorch and CUDA can be found at dockerhub/pytorch.

Install mmcv-lite

If you need to use PyTorch-related modules, make sure PyTorch has been successfully installed in your environment by referring to the PyTorch official installation guide.

pip install mmcv-lite
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值