anaconda环境更改gcc版本并编译Pytorch3D 0.4.0

项目需要编译pytorch3D 0.4.0且需要gcc 7以上且8以下的版本(尝试了5.4.0和12.2.0均报错),所以打算安装7.3.0版本的gcc,但是服务器没有root权限,所以只能在conda环境下更改gcc版本。
于是参考博客anaconda新建虚拟环境更改gcc7.3版本,且不改变本机gcc

升级gcc与g++

升级gcc到7.3.0

conda install -c moussi gcc_impl_linux-64

升级gxx到7.3.0

conda install -c moussi gxx_impl_linux-64

修改gcc软链接

ln -s ~/anaconda3/envs/(envs_name)/bin/x86_64-conda_cos6-linux-gnu-gcc  ~/anaconda3/envs/(envs_name)/bin/gcc

修改g++软链接

ln -s ~/anaconda3/envs/(envs_name)/libexec/gcc//bin/x86_64-conda_cos6-linux-gnu-g++  ~/anaconda3/envs/(envs_name)/bin/g++

此时查看gcc与g++版本

gcc -v
Reading specs from ~/anaconda3/envs/(envs_name)/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/specs
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=~/anaconda3/envs/(envs_name)/bin/../libexec/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-conda_cos6-linux-gnu
Configured with: /home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=x86_64-conda_cos6-linux-gnu --prefix=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/gcc_built --with-sysroot=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot --enable-languages=c,c++,fortran,objc,obj-c++ --with-pkgversion='crosstool-NG 1.23.0.450-d54ae' --enable-__cxa_atexit --disable-libmudflap --enable-libgomp --disable-libssp --enable-libquadmath --enable-libquadmath-support --enable-libsanitizer --enable-libmpx --with-gmp=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-mpfr=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-mpc=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-isl=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot --enable-long-long --enable-default-pie
Thread model: posix
gcc version 7.3.0 (crosstool-NG 1.23.0.450-d54ae)
g++ -v
Reading specs from ~/anaconda3/envs/(envs_name)/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/specs
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=~/anaconda3/envs/(envs_name)/bin/../libexec/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-conda_cos6-linux-gnu
Configured with: /home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=x86_64-conda_cos6-linux-gnu --prefix=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/gcc_built --with-sysroot=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot --enable-languages=c,c++,fortran,objc,obj-c++ --with-pkgversion='crosstool-NG 1.23.0.450-d54ae' --enable-__cxa_atexit --disable-libmudflap --enable-libgomp --disable-libssp --enable-libquadmath --enable-libquadmath-support --enable-libsanitizer --enable-libmpx --with-gmp=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-mpfr=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-mpc=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-isl=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1580517382604/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot --enable-long-long --enable-default-pie
Thread model: posix
gcc version 7.3.0 (crosstool-NG 1.23.0.450-d54ae) 

编译pytorch3D

此后进行pytorch3D编译

报错1

出现报错:

subprocess.CalledProcessError: Command '['which', '~/anaconda3/envs/(envs_name)/bin/x86_64-conda-linux-gun-c++']' returned non-zero exit status 1.

分析原因是没有在指定路径下找到‘x86_64-conda-linux-gun-c++’
这时可以使用find命令查找路径下的‘x86_64-conda-linux-gun-c++’

find ~/anaconda3/envs/(envs_name)/ -name *c++

发现该路径下有文件’x86_64-conda_cos6-linux-gnu-c++',于是将其复制为‘x86_64-conda-linux-gun-c++’。

cp ~/anaconda3/envs/(envs_name)/bin/x86_64-conda_cos6-linux-gun-c++ ~/anaconda3/envs/(envs_name)/bin/x86_64-conda-linux-gun-c++

问题解决

报错2

又出现报错:

~/anaconda3/envs/(envs_name)/bin/x86_64-conda-linux-gnu-cc: No such file or directory

和上个问题是一样的,我们只需要再复制另一个文件过来就可以了

cp ~/anaconda3/envs/(envs_name)/bin/x86_64-conda_cos6-linux-gun-cc ~/anaconda3/envs/(envs_name)/bin/x86_64-conda-linux-gun-cc

问题解决

报错3

又出现报错

error: [Errno 2] No such file or directory: '~/anaconda3/envs/(envs_name)/lib/python3.6/site-packages/yacs-0.1.8.dist-info/METADATA'

尝试安装yacs

pip install yacs

但报错

Requirement already satisfied: yacs in ~/anaconda3/envs/(envs_name)/lib/python3.6/site-packages (0.1.8)
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '~/anaconda3/envs/(envs_name)/lib/python3.6/site-packages/yacs-0.1.8.dist-info/METADATA'

于是尝试reinstall yacs

pip install --force-reinstall --no-deps yacs==0.1.8

依然报错,报错内容还让我们输入这条报错指令

Collecting yacs==0.1.8
  Using cached yacs-0.1.8-py3-none-any.whl (14 kB)
Installing collected packages: yacs
  Attempting uninstall: yacs
    Found existing installation: yacs 0.1.8
ERROR: Cannot uninstall yacs 0.1.8, RECORD file not found. You might be able to recover from this via: 'pip install --force-reinstall --no-deps yacs==0.1.8'.

查阅网络发现以下指令

pip install --ignore-installed yacs==0.1.8 -i https://mirrors.aliyun.com/pypi/simple/

成功安装yacs,只有一条警告,未报错

Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting yacs==0.1.8
  Downloading https://mirrors.aliyun.com/pypi/packages/38/4f/fe9a4d472aa867878ce3bb7efb16654c5d63672b86dc0e6e953a67018433/yacs-0.1.8-py3-none-any.whl (14 kB)
Collecting PyYAML
  Downloading https://mirrors.aliyun.com/pypi/packages/b3/85/79b9e5b4e8d3c0ac657f4e8617713cca8408f6cdc65d2ee6554217cedff1/PyYAML-6.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (603 kB)
     |████████████████████████████████| 603 kB 28.9 MB/s            
WARNING: Error parsing requirements for yacs: [Errno 2] No such file or directory: '~/anaconda3/envs/(envs_name)/lib/python3.6/site-packages/yacs-0.1.8.dist-info/METADATA'
Installing collected packages: PyYAML, yacs
Successfully installed PyYAML-6.0 yacs-0.1.8

后来又出现了缺少包的报错,通过查阅网络解决。
至此pytorch3D编译成功

你可能感兴趣的:(pytorch,python,anaconda,gcc,深度学习)