torch环境安装/问题整理

1、创建conda虚拟环境:

1.1 创建命令

conda create -n torch1121+cuda10.2 python==3.8

1.2 激活命令

conda activate torch1121+cuda10.2

问题1:

Collecting package metadata (current_repodata.json): failed

UnavailableInvalidChannel: The channel is not accessible or is invalid.
  channel name: anaconda/pkgs/main
  channel url: http://mirrors.ustc.edu.cn/anaconda/pkgs/main
  error code: 404

You will need to adjust your conda configuration to proceed.
Use `conda config --show channels` to view your configuration's current state,
and use `conda config --show-sources` to view config file locations.


(base) [chenghan@localhost ~]$ conda create -n torch1121+cuda10.2 python==3.9
Collecting package metadata (current_repodata.json): failed

UnavailableInvalidChannel: The channel is not accessible or is invalid.
  channel name: anaconda/pkgs/main
  channel url: http://mirrors.ustc.edu.cn/anaconda/pkgs/main
  error code: 404

You will need to adjust your conda configuration to proceed.
Use `conda config --show channels` to view your configuration's current state,
and use `conda config --show-sources` to view config file locations.

解决方法1:

输入以下命令:

conda config --remove-key channels

2、查看cuda版本

2.1 输入以下命令查看所有的cuda版本

ls -l /usr/local | grep cuda
lrwxrwxrwx   1 root root  20 33 2021 cuda -> /usr/local/cuda-10.0
drwxr-xr-x. 19 root root 274 33 2021 cuda-10.0
drwxr-xr-x  15 root root 288 222 2021 cuda-10.2
drwxr-xr-x. 18 root root 249 87 2020 cuda-9.0
drwxr-xr-x. 18 root root 249 927 2020 cuda-9.2

2.2 输入以下命令查看当前的cuda版本:

nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

3、安装pytorch
根据自己的cuda版本以及pytorch在torch官网上找对应的安装命令:pytorch官网

conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=10.2 -c pytorch

3、安装mmcv-full

问题1

利用pip install mmcv-full==1.7.0以下命令出现以下问题:

 /home/chenghan/anaconda3/envs/torch1121+cuda10.2/lib/python3.9/site-packages/torch/utils/cpp_extension.py:820: UserWarning: There are no g++ version bounds defined for CUDA version 10.0
        warnings.warn(f'There are no {compiler_name} version bounds defined for CUDA version {cuda_str_version}')
      building 'mmcv._ext' extension
      creating build/temp.linux-x86_64-cpython-39
      creating build/temp.linux-x86_64-cpython-39/mmcv
      creating build/temp.linux-x86_64-cpython-39/mmcv/ops
      creating build/temp.linux-x86_64-cpython-39/mmcv/ops/csrc
      creating build/temp.linux-x86_64-cpython-39/mmcv/ops/csrc/pytorch
      creating build/temp.linux-x86_64-cpython-39/mmcv/ops/csrc/pytorch/cpu
      creating build/temp.linux-x86_64-cpython-39/mmcv/ops/csrc/pytorch/cuda
      gcc -pthread -B /home/chenghan/anaconda3/envs/torch1121+cuda10.2/compiler_compat -Wl,--sysroot=/ -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -Wall -fPIC -O2 -isystem /home/chenghan/anaconda3/envs/torch1121+cuda10.2/include -fPIC -O2 -isystem /home/chenghan/anaconda3/envs/torch1121+cuda10.2/include -fPIC -DMMCV_WITH_CUDA -I/tmp/pip-install-3lhqn1mt/mmcv-full_c677e90658ad44a9b18bb7f3de410076/mmcv/ops/csrc/pytorch -I/tmp/pip-install-3lhqn1mt/mmcv-full_c677e90658ad44a9b18bb7f3de410076/mmcv/ops/csrc/common -I/tmp/pip-install-3lhqn1mt/mmcv-full_c677e90658ad44a9b18bb7f3de410076/mmcv/ops/csrc/common/cuda -I/home/chenghan/anaconda3/envs/torch1121+cuda10.2/lib/python3.9/site-packages/torch/include -I/home/chenghan/anaconda3/envs/torch1121+cuda10.2/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -I/home/chenghan/anaconda3/envs/torch1121+cuda10.2/lib/python3.9/site-packages/torch/include/TH -I/home/chenghan/anaconda3/envs/torch1121+cuda10.2/lib/python3.9/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/chenghan/anaconda3/envs/torch1121+cuda10.2/include/python3.9 -c ./mmcv/ops/csrc/pytorch/active_rotated_filter.cpp -o build/temp.linux-x86_64-cpython-39/./mmcv/ops/csrc/pytorch/active_rotated_filter.o -std=c++14 -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -DTORCH_EXTENSION_NAME=_ext -D_GLIBCXX_USE_CXX11_ABI=0
      gcc: 错误:unrecognized command line option ‘-std=c++14’
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mmcv-full
  Running setup.py clean for mmcv-full
Failed to build mmcv-full
ERROR: Could not build wheels for mmcv-full, which is required to install pyproject.toml-based projects
(torch1121+cuda10.2) [chenghan@localhost ADNet-master]$ pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.10/index.html
Looking in links: https://download.openmmlab.com/mmcv/dist/cu102/torch1.10/index.html
^CERROR: Operation cancelled by user

解决方法1

修改命令行中的cu102和torch1.12版本号:

pip install mmcv-full==1.7.0 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.12/index.html

4、pip install 镜像源地址

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

5、gcc版本问题

问题1:

gcc: error: unrecognized command line option ‘-std=c++14’ error: command ’

解决方法:

升级gcc版本,无root权限Linux升级gcc版本

下载并解压所需版本(可直接改自己所需要的版本)

wget http://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz
tar -zxvf gcc-7.4.0.tar.gz
cd gcc-7.4.0
./contrib/download_prerequisites

编译,安装(修改–prefix=/home/username的地址,以及版本号)

cd gcc-5.4.0
mkdir objdir  
cd objdir
../configure --disable-checking --enable-languages=c,c++ --disable-multilib --prefix=/home/username/gcc-7.4 --enable-threads=posix
make
make install

设置环境变量(修改两个地址,与编译、安装地址保持一致)

vim ~/.bashrc
export PATH=/home/username/gcc-5.4/bin:/home/username/gcc-5.4/lib64:$PATH
export LD_LIBRARY_PATH=/home/username/gcc-5.4/lib/:$LD_LIBRARY_PATH
source ~/.bashrc

vim的简单用法:
shift+i:可编辑状态
Esc:为编辑完之后进入可读模式
shift+q:退出状态
wq:表示保存退出

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值