前言
pytorch 3d库,用于3d显示和处理
官方版本及安装指引如下
bash
https://github.com/facebookresearch/pytorch3d/releases
https://github.com/facebookresearch/pytorch3d/blob/main/INSTALL.md
安装方式
直接pip install pytorch3d 是安装不上的,可以用以下方式
1、换成conda安装
conda install pytorch3d -c pytorch3d
2、pip 安装
如果想让环境干净一点,可以使用pip 安装git仓库
代码如下
bash
pip install "git+https://github.com/facebookresearch/pytorch3d.git"
#特定版本
pip install "git+https://github.com/facebookresearch/pytorch3d.git@stable"
pip install "git+https://github.com/facebookresearch/pytorch3d.git@v0.7.7"
但是可能会遇到No module named 'torch'的问题,尽管自己的conda环境已经安装了torch,问题如下

这是由于环境没有隔离,pytorch3d 的 setup.py 会在"获取构建依赖"阶段 单独创建一个临时的 pip build-env,这个 build 环境里,并不会自动带上conda环境中的 torch,因此执行 import torch 就会失败,pip 构建隔离(PEP 517)导致的,不是 torch 不在你的环境,而是在 pytorch3d 的构建沙箱里 torch 不存在。
pip install 问题解决
禁用构建隔离
bash
pip install git+https://github.com/facebookresearch/pytorch3d.git@v0.7.7 --no-build-isolation
或
bash
git clone https://github.com/facebookresearch/pytorch3d.git
cd pytorch3d
git checkout v0.7.7
pip install . --no-build-isolation
其中v0.7.7是要安装的版本,可以在https://github.com/facebookresearch/pytorch3d/releases中获取你torch和python对应的版本