Building wheel for mmcv-full (setup.py) ... error和OSError: CUDA_HOME environment variable is not set

安装和使用mmdetection中遇到的一些问题:

    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'mmcv._ext'

这是安装mmcv,而不是安装mmcv-full导致功能不全的问题,pip install mmcv-full时,还有下面这种情况:

 Building wheel for mmcv-full (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/xiejun/anaconda3/envs/xiejun/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5sje9kee/mmcv-full_d11bcf00f28c4d2cab43de59499a7362/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5sje9kee/mmcv-full_d11bcf00f28c4d2cab43de59499a7362/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-c1qginh5
       cwd: /tmp/pip-install-5sje9kee/mmcv-full_d11bcf00f28c4d2cab43de59499a7362/
.
..
...
Failed to build mmcv-full
Installing collected packages: mmcv-full
    Running setup.py install for mmcv-full ... error
    ERROR: Command errored out with exit status 1:
     command: /home/xiejun/anaconda3/envs/xiejun/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5sje9kee/mmcv-full_d11bcf00f28c4d2cab43de59499a7362/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5sje9kee/mmcv-full_d11bcf00f28c4d2cab43de59499a7362/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-9jhxpj3o/install-record.txt --single-version-externally-managed --compile --install-headers /home/xiejun/anaconda3/envs/xiejun/include/python3.7m/mmcv-full
.
.
.
RuntimeError: Error compiling objects for extension
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/xiejun/anaconda3/envs/xiejun/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5sje9kee/mmcv-full_d11bcf00f28c4d2cab43de59499a7362/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5sje9kee/mmcv-full_d11bcf00f28c4d2cab43de59499a7362/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-9jhxpj3o/install-record.txt --single-version-externally-managed --compile --install-headers /home/xiejun/anaconda3/envs/xiejun/include/python3.7m/mmcv-full Check the logs for full command output.

解决mmcv的安装问题,可以看这篇博客,这是我整理的在ubuntu中安装mmdetection成功配置的过程:https://blog.csdn.net/qq_44442727/article/details/113444207
我安装的时候,一开始我是pip install mmcv 很顺利就装完了,但是一运行就报错:ModuleNotFoundError: No module named ‘mmcv._ext’
官网也有提到mmcv功能不全,最好装mmcv-full,我后面是卸载了mmcv,安装mmcv-full.
mmcv-full的安装先要查询版本是否匹配,这个看官网:https://github.com/open-mmlab/mmcv
Building wheel for mmcv-full (setup.py) ... error和OSError: CUDA_HOME environment variable is not set_第1张图片

我的torch版本是1.7.1+cu101,所以找到torch1.7和cuda相交位置的“install”点开黑色三角形,可以看到指令:

pip install mmcv-full=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.0/index.html

上面指令中{mmcv_version}是待定的,需要具体确定,这时结合mmdetection的版本,如下图,因为我安装的是最新版的mmdetection,已经到了2.8.0版本了,mmcv-full的版本要求在>=1.2.4,<1.3于是我选择1.2.4版本。
Building wheel for mmcv-full (setup.py) ... error和OSError: CUDA_HOME environment variable is not set_第2张图片

安装指令具体为:

pip install mmcv-full==1.2.4 -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.0/index.html

完成后,这样就顺利安装好了。主要还是一个版本问题,mmdetection的版本+cuda的版本+显卡驱动的版本,版本对应上了,按上述方法安装,基本没有问题。

还碰到的一个问题是:

OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA.

这个就是在电脑上安装了cuda,但是没有添加环境变量,库在调用的过程中找不到路径,没法调用,就报错了。解决办法就是添加环境变量:

vim ~/.bashrc

进入环境变量配置文件:
Building wheel for mmcv-full (setup.py) ... error和OSError: CUDA_HOME environment variable is not set_第3张图片
按“a”进行编辑,添加如下内容至文末:

export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

再安Esc改变模式,保存编辑退出,指令是(:wq)
退出后,进行更新:

source ~/.bashrc

可以使用如下指令进行验证:

cat /proc/driver/nvidia/version

结果是:

NVRM version: NVIDIA UNIX x86_64 Kernel Module  435.21  Sun Aug 25 08:17:57 CDT 2019
GCC version:  gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) 

输入:

nvcc -V

结果:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

这就可以查询到cuda的信息了,成功添加好了环境变量。

你可能感兴趣的:(mmdetection,linux,python,cuda,ubuntu,深度学习)