nerfstudio icon indicating copy to clipboard operation
nerfstudio copied to clipboard

OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

Open 2feet6inches opened this issue 1 year ago • 3 comments

$ pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 -f https://download.pytorch.org/whl/torch_stable.html
pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch==1.12.1+cu113
  Using cached https://download.pytorch.org/whl/cu113/torch-1.12.1%2Bcu113-cp38-cp38-linux_x86_64.whl (1837.7 MB)
Collecting torchvision==0.13.1+cu113
  Using cached https://download.pytorch.org/whl/cu113/torchvision-0.13.1%2Bcu113-cp38-cp38-linux_x86_64.whl (23.4 MB)
Collecting typing-extensions
  Using cached typing_extensions-4.4.0-py3-none-any.whl (26 kB)
Collecting requests
  Using cached requests-2.28.1-py3-none-any.whl (62 kB)
Collecting pillow!=8.3.*,>=5.3.0
  Using cached Pillow-9.2.0-cp38-cp38-manylinux_2_28_x86_64.whl (3.2 MB)
Collecting numpy
  Using cached numpy-1.23.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB)
Collecting urllib3<1.27,>=1.21.1
  Using cached urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting charset-normalizer<3,>=2
  Using cached charset_normalizer-2.1.1-py3-none-any.whl (39 kB)
Requirement already satisfied: certifi>=2017.4.17 in ./anaconda3/envs/nerfstudio/lib/python3.8/site-packages (from requests->torchvision==0.13.1+cu113) (2022.9.24)
Installing collected packages: urllib3, typing-extensions, pillow, numpy, idna, charset-normalizer, torch, requests, torchvision
Successfully installed charset-normalizer-2.1.1 idna-3.4 numpy-1.23.3 pillow-9.2.0 requests-2.28.1 torch-1.12.1+cu113 torchvision-0.13.1+cu113 typing-extensions-4.4.0 urllib3-1.26.12
Collecting git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
  Cloning https://github.com/NVlabs/tiny-cuda-nn/ to /tmp/pip-req-build-p95k6ytq
  Running command git clone --filter=blob:none --quiet https://github.com/NVlabs/tiny-cuda-nn/ /tmp/pip-req-build-p95k6ytq
  Resolved https://github.com/NVlabs/tiny-cuda-nn/ to commit 563b626c298a88b5a0c6fb47944c693e9fbd8507
  Running command git submodule update --init --recursive -q
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-req-build-p95k6ytq/bindings/torch/setup.py", line 111, in <module>
          ext = CUDAExtension(
        File "/home/kosuke/anaconda3/envs/nerfstudio/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 983, in CUDAExtension
          library_dirs += library_paths(cuda=True)
        File "/home/kosuke/anaconda3/envs/nerfstudio/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1098, in library_paths
          if (not os.path.exists(_join_cuda_home(lib_dir)) and
        File "/home/kosuke/anaconda3/envs/nerfstudio/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 2125, in _join_cuda_home
          raise EnvironmentError('CUDA_HOME environment variable is not set. '
      OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.
      Building PyTorch extension for tiny-cuda-nn version 1.6
      Obtained compute capability 80 from PyTorch
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

2feet6inches avatar Oct 08 '22 14:10 2feet6inches

This looks like an issue with the tinycudann library. Looking through their Github issues, at least one other person had this issue - https://github.com/NVlabs/tiny-cuda-nn/issues/160 Their solution isn't particularly promising, if you are still having this issue you may want to reopen this issue.

tancik avatar Oct 10 '22 01:10 tancik

I'm getting this same error, on Linux, with a 2070 Super. I tried rebooting and that did not help. I've tried installing the full CUDA install with Anaconda and that led to gcc version errors and a whole bunch of issues. I then tried restarting a new Anaconda environment and doing the quickstart again, and same issue. Not sure what my CUDA_HOME should be since I'm using Pytorch's included runtime, I think?

venatiodecorus avatar Oct 10 '22 01:10 venatiodecorus

Oh so I had to install the cuda package. I thought pytorch came with the runtime bits. But I was able to get past this step after installing cuda via pacman.

venatiodecorus avatar Oct 10 '22 02:10 venatiodecorus

Same issue for me. I am on WSL2, wonder whether its an issue with it. (Btw, I have stable diffusion running smoothly in 3060)

smokeyhallow avatar Oct 16 '22 07:10 smokeyhallow

Also getting this error on Ubuntu 22.04

But I was able to get past this step after installing cuda via pacman.

on Ubuntu, even though I have cudatoolkit 11.3.1 in my conda env for nerfstudio, I still get this error.

I tried to follow the recommended official instructions for installing CUDA from Nvidia outside of conda; https://developer.nvidia.com/cuda-downloads

However this ended up breaking my Ubuntu installation since it appears to have updated my Nvidia drivers to a version that is not actually compatible with my graphics card (RTX 3060)

How are you "supposed" to install CUDA in order to get it to work with nerfstudio's env setup guidelines?

stevekm avatar Oct 18 '22 20:10 stevekm

Ok, it seems that I was able resolve it with this; https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#conda-installation

$ conda install -c nvidia cuda

which installed CUDA version 11.8.0 into my conda env, and let me install this sucessfully;

$ pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch

which let me run

$ ns-train nerfacto

Maybe we can get cuda put in the conda env installation instructions for nerfstudio?

stevekm avatar Oct 18 '22 20:10 stevekm

I worry that there are many different ways to install cuda that can conflict with each other. I think it may be difficult to provide a single set of instructions that work for everyone. (This is why we originally did not include them).

tancik avatar Oct 18 '22 20:10 tancik

I think it would be a good idea to at least note in the README that CUDA needs to be installed, and possibly provide some links or docs on various ways to install it. As it stands currently, I was under the impression that the README install guide included everything necessary to run nerfstudio out of the box, including CUDA installation, especially because (confusingly) some of the Python libraries included in the installation have "cuda" in the name.

stevekm avatar Oct 18 '22 21:10 stevekm

Yea good idea. I added a short blurb, hopefully it will prevent this confusion in the future. I'm going to close this issue, feel free to reopen if you don't think it is resolved.

tancik avatar Oct 18 '22 23:10 tancik