当前位置:   article > 正文

Ubuntu20.04安装pytorch3d踩坑记录

Ubuntu20.04安装pytorch3d踩坑记录

写在前面

显卡:RTX4070Ti
Anaconda 23.3.1
Ubuntu20.04 LTS
pytorch3d官方发布链接:https://github.com/facebookresearch/pytorch3d/blob/main/INSTALL.md

一、最终成功的版本

conda create -n pytorch3d python=3.9
conda activate pytorch3d
conda install pytorch=1.13.0 torchvision pytorch-cuda=11.6 -c pytorch -c nvidia
conda install -c fvcore -c iopath -c conda-forge fvcore iopath
conda install -c bottler nvidiacub
conda install pytorch3d -c pytorch3d
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

测试代码:

import sys
import torch
import pytorch3d
from pytorch3d.utils import ico_sphere
from pytorch3d.io import load_obj
from pytorch3d.structures import Meshes
from pytorch3d.ops import sample_points_from_meshes
from pytorch3d.loss import chamfer_distance

pyt_version_str=torch.__version__.split("+")[0].replace(".", "")
version_str="".join([
    f"py3{sys.version_info.minor}_cu",
    torch.version.cuda.replace(".",""),
    f"_pyt{pyt_version_str}"
])

print(version_str)
print(torch.cuda.is_available())
print(torch.version.cuda)
print(pytorch3d.__version__)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

输出为:

py39_cu116_pyt1130
True
11.6
0.7.5
  • 1
  • 2
  • 3
  • 4

安装成功

二、踩坑记录

第一次:
python =3.8,pytorch=2.1.0, cuda12.1
安装指令

conda create -n pyt3d python=3.8
conda activate pyt3d
conda install pytorch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 pytorch-cuda=12.1 -c pytorch -c nvidia
conda install -c fvcore -c iopath -c conda-forge fvcore iopath
conda install -c bottler nvidiacub
pip install black usort flake8 flake8-bugbear flake8-comprehensions
conda install pytorch3d -c pytorch3d
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

报错:

Package gst-plugins-base conflicts for:
pyqt -> qt-main=5.15 -> gst-plugins-base[version='>=1.12.2,<1.13.0a0|>=1.12.4,<1.13.0a0|>=1.14.0,<1.15.0a0|>=1.14.1,<1.15.0a0']
qt-main -> gst-plugins-base[version='>=1.14.0,<1.15.0a0|>=1.14.1,<1.15.0a0']The following specifications were found to be incompatible with your system:

  - feature:/linux-64::__cuda==12.2=0
  - feature:/linux-64::__glibc==2.31=0
.....手动省略
  - zlib -> libgcc-ng[version='>=11.2.0'] -> __glibc[version='>=2.17']
  - zstd -> libgcc-ng[version='>=11.2.0'] -> __glibc[version='>=2.17']

Your installed version is: 2.31

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

尝试去pytorch3d官方gthub问题板块找解决办法:
Can’t install pytorch3d using conda -> glibc error #1076
pytorch3d安装|踩坑指南

  1. 包括但不限于,从conda源找到对应的pytorch3d包下载到本地安装。
    下载地址:https://anaconda.org/pytorch3d/pytorch3d/files
    虽然我用这个办法没有成功,但是我还是把这个方法记下来,指不定下次哪个解决办法有用呢
    如何判断需要安装哪个pytorch3d呢?python运行下述代码,会输出一个py38_cu121_pyt210字符串,其中38是python的版本号,121是cuda的版本号12.1,210是pytorch的版本号,去pytorch3d的下载链接下载对应的文件。然后用conda install linux-64_pytorch3d-0.7.5-py38_cu121_pyt210.tar.bz2安装
pyt_version_str=torch.__version__.split("+")[0].replace(".", "")
version_str="".join([
    f"py3{sys.version_info.minor}_cu",
    torch.version.cuda.replace(".",""),
    f"_pyt{pyt_version_str}"
])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

用这个方法我安装成功,但是导入from pytorch3d.utils import ico_sphere这一句时报错:

ImportError: /xxxx/pytorch3d/pytorch3d/_C.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN3c105ErrorC2ENS_14SourceLocationENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE 
  • 1

又去官方issue找解决办法,就是各种试不同的python版本/cuda版本和pytorch版本的组合。最后试出了最终成功的版本,然后我发现这个组合和官方提供的一样,。。。。。。。
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】

推荐阅读
相关标签