Alex Dima
Alex Dima

Reputation: 21

Installing PyTorch3D fails with anaconda and pip on Windows 10

I saw that more people seem to have the same issue, but it was not resolved. I am trying to install Pytorch3D with Anaconda and got the following PackageNotFound error.

Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. Collecting package metadata (repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
  - pytorch3d
Current channels:
  - https://conda.anaconda.org/pytorch3d/win-64
  - https://conda.anaconda.org/pytorch3d/noarch
  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch
To search for alternate channels that may provide the conda package you're looking for, navigate to
    https://anaconda.org
and use the search bar at the top of the page.

enter image description here enter image description here

I have also tried using pip install 'git+https://github.com/facebookresearch/pytorch3d.git' and get the following:

C:\Users\Alexandra>pip install 'git+https://github.com/facebookresearch/pytorch3d.git'
ERROR: Invalid requirement: "'git+https://github.com/facebookresearch/pytorch3d.git'"

C:\Users\Alexandra>pip install git+https://github.com/facebookresearch/pytorch3d.git
Collecting git+https://github.com/facebookresearch/pytorch3d.git
  Cloning https://github.com/facebookresearch/pytorch3d.git to c:\users\alexan~1\appdata\local\temp\pip-req-build-uspo7an4
  Running command git clone -q https://github.com/facebookresearch/pytorch3d.git 'C:\Users\ALEXAN~1\AppData\Local\Temp\pip-req-build-uspo7an4'
  ERROR: Error [WinError 2] The system cannot find the file specified while executing command git clone -q https://github.com/facebookresearch/pytorch3d.git 'C:\Users\ALEXAN~1\AppData\Local\Temp\pip-req-build-uspo7an4'
ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?

I am on Windows 10, using python 3.8, PyTorch 1.5 and CUDA 10.2. I am very new to python, so I have no idea how to fix this (you can tell, that I've never installed from git before..) (please be lenient!) Thank you!

EDIT: Thank you for your answers. I did install Git and it got me a bit further, but still not completeing the build..

Screenshot 3

Also, interesting enough, when I run the commands

!pip install torch torchvision
!pip install 'git+https://github.com/facebookresearch/pytorch3d.git@stable'

in Google Collab it seems to work, but I cannot run it , let's say, in jupyter. Any more ideas?

Upvotes: 1

Views: 18232

Answers (4)

aprath
aprath

Reputation: 76

I was just now able to get the pytorch3d installation in windows 11 via PIP. Here are the version details

torch       1.13.1+cu116
torchvision 0.14.1+cu116
fvcore      0.1.5.post20221221
iopath      0.1.10
pytorch3d   0.7.2

NOTE: fvcore and iopath will be installed directly while installing pytorch3d (step4)

Installation steps:

  1. install pytorch 1.13.1 with cuda 11.6 (make sure the gpu driver is uptodate)

    python -m pip install torch==1.13.1 torchvision --index-url https://download.pytorch.org/whl/cu116

  2. install the cuda toolkit version 11.6 fro windows 11 from official source

  3. set the CUDA_HOME path

# if powershell
$env:CUDA_HOME="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6"
# if windows cmd terminal 
set CUDA_HOME=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
  1. clone the pytorch3d repo; checkout version v0.7.2. Add some modifications to circumvent error while compiling marching cubes - repo commit 3388d3, and then install
git clone --branch v0.7.2 https://github.com/facebookresearch/pytorch3d.git 
cd pytorch3d
git cherry-pick 3388d3
python setup.py install

Upvotes: 0

Jaeyoon Jeong
Jaeyoon Jeong

Reputation: 699

Recently, I succeded installing pytorch3d in windows 10/11 with latest version of pytorch(1.13.1).

As Pytorch3D has some dependency with cuda, it has a little complexity to build from source. But it can be solved anyway.

(1) First, install cuda 11.6 windows and check enviroment variable. enter image description here

As someone pointed in this article, CUB_HOME path variable is not needed, as we use 11.6 cuda toolkit.

(2) Then install pytorch latest, in my case 1.13.1 with conda tool.(When I tried pip version, it was not successful.)

conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia

(3) Install needed packages with Conda. You can check it with INSTALL.md in pytorh3d source.

conda install -c fvcore -c iopath -c conda-forge fvcore iopath

(4) Check build tool. we can build it with Visual Studio 2019 C++ package with compiler v142. you can check it with Visual Studio Installer. enter image description here

(5) Run x64 native build tool then move to pytorch3d source enter image description here

(6) install it with ...

python setup.py install

enter image description here

Upvotes: 2

B200011011
B200011011

Reputation: 4268

Edit 10-17-2022

With CUDA 11.6 downloading CUB and setting CUB_HOME is no longer necessary. Trying to use CUB_HOME will give nvcc.exe compile error. Any previous CUB_HOME environment variable should be deleted and command line restarted before running setup.


Original Answer

I have also tried to install pytorch3d on windows 10. As of writing this there is no windows package in, https://anaconda.org/pytorch3d/pytorch3d.

Pytorch3d install doc has detailed instructions but some information is missing and only found inside various issues. Following various issues I was able get pytorch3d installed by compiling from source on pytorch 1.8.1 and 1.10.0(This version is not supported yet in official docs for pytorch3d 0.6.0).

I have tested on pytorch 1.8.1 with CUDA 10.2 and pytorch 1.10.0 with CUDA 11.3. I had CUDA Toolkit 11.0, CuDNN installed separately with environment variables set to be used by tensorflow gpu. For both environment a new python 3.9 was used. Visual studio 16.11.5 was used with Desktop Development with C++ enabled, CMake 3.21.3.

It is probably better to have same CUDA Toolkit version as the Pytorch GPU version. There was warning regarding version but in my case it was installed successfully.

The pytorch3d source code must be downloaded and extracted in order to compile. When running python setup.py install from pytorch3d folder it looked for CUDA_HOME. It was able to find correct CUDA path probably based on other flags.

I initially faced these errors,

  • RuntimeError: Error compiling objects for extension.
  • xutility(...): error: expected a "("

Install on windows

  • Create conda enviroment, install torch and dependencies.
conda create -n pytorch3d python=3.9
conda activate pytorch3d
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
conda install -c fvcore -c iopath -c conda-forge fvcore iopath
  • Install appropriate CUDA Toolkit, CuDNN and set enviroment variables.
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\extras\CUPTI\lib64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include
  • Set correct path to cl.exe Visual C++ compiler. This will allow to run compilation from conda prompt with correct environment selected. Host x64 was used and x86 for the folder inside as x64 one gave error for me. In my case it was,
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x86
  • Following this issue, PYTORCH3D_NO_NINJA system environment variable was set with value of 1.

  • FORCE_CUDA with value of 1 (though not required if CUDA is available in pytorch) and CUB_HOME system environment variable was set by downloading it from, https://github.com/NVIDIA/cub/releases.

PYTORCH3D_NO_NINJA 1
CUB_HOME C:\portable\cub-1.9.9
  • The following env variable were probably set by CUDA Toolkit install.
CUDA_PATH_V11_0 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0
CUDA_PATH C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0
  • Following this issue instead of removing -std=c++14 from extra_compile_args in setup.py, commenting out "-std=c++14" in nvcc_args worked for me. I did check if the suggested method in the issue works.

  • Now running python setup.py install from pytorch3d source folder should start compile and install it.

  • Install following requirements in conda env to run demos and examples.

conda install jupyter
pip install scikit-image matplotlib imageio plotly opencv-python

Some of the steps mentioned above is probably not needed. There is no need to modify any header files. This is the source that worked for me, https://github.com/facebookresearch/pytorch3d/tree/bfeb82efa38f29ed5b9cf8d8986fab744fe559ea.

Upvotes: 5

r23
r23

Reputation: 1

https://github.com/facebookresearch/pytorch3d/blob/master/INSTALL.md

Install from local clone on Windows:

If you are using pre-compiled pytorch 1.4 and torchvision 0.5, you should make the following changes to the pytorch source code to successfully compile with Visual Studio 2019 (MSVC 19.16.27034) and CUDA 10.1.

Change python/Lib/site-packages/torch/include/csrc/jit/script/module.h

L466, 476, 493, 506, 536

-static constexpr * +static const *

Change python/Lib/site-packages/torch/include/csrc/jit/argument_spec.h

L190

-static constexpr size_t DEPTH_LIMIT = 128; +static const size_t DEPTH_LIMIT = 128;

Change python/Lib/site-packages/torch/include/pybind11/cast.h

L1449

-explicit operator type&() { return *(this->value); } +explicit operator type& () { return ((type)(this->value)); }

After patching, you can go to "x64 Native Tools Command Prompt for VS 2019" to compile and install

cd pytorch3d python3 setup.py install

After installing, verify whether all unit tests have passed

cd tests python3 -m unittest discover -p *.py

Upvotes: 0

Related Questions