nerfstudio-project / nerfacc

A General NeRF Acceleration Toolbox in PyTorch.
https://www.nerfacc.com/
Other
1.37k stars 113 forks source link

ImportError: cannot import name 'csrc' from 'nerfacc' #156

Closed bolopenguin closed 1 year ago

bolopenguin commented 1 year ago

Hello,

I am trying to run this simple script using nerfacc:

import nerfacc
import torch

aabb = torch.tensor([0.0, 0.0, 0.0, 1.0, 1.0, 1.0], device="cuda:0")
rays_o = torch.rand((128, 3), device="cuda:0")
rays_d = torch.randn((128, 3), device="cuda:0")
rays_d = rays_d / rays_d.norm(dim=-1, keepdim=True)
t_min, t_max = nerfacc.ray_aabb_intersect(rays_o, rays_d, aabb)
print(t_min)

In the virtual enviroment I have installed torch and nerfacc:

pip install torch --extra-index-url https://download.pytorch.org/whl/cu116
pip install nerfacc

Python version: 3.8.10 CUDA version: 11.6 pytorch version: 1.13.1+cu116 OS: Ubuntu 20.04

But I got the following error:

Traceback (most recent call last):
  File "/xxx/venv/test/lib/python3.8/site-packages/nerfacc/cuda/_backend.py", line 50, in <module>
    from nerfacc import csrc as _C
ImportError: cannot import name 'csrc' from 'nerfacc' (/xxx/venv/test/lib/python3.8/site-packages/nerfacc/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "eyenerf/net/x.py", line 8, in <module>
    t_min, t_max = nerfacc.ray_aabb_intersect(rays_o, rays_d, aabb)
  File "/xxx/venv/test/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/xxx/venv/test/lib/python3.8/site-packages/nerfacc/intersection.py", line 47, in ray_aabb_intersect
    t_min, t_max = _C.ray_aabb_intersect(rays_o, rays_d, aabb)
  File "/xxx/venv/test/lib/python3.8/site-packages/nerfacc/cuda/__init__.py", line 11, in call_cuda
    from ._backend import _C
  File "/xxx/test/lib/python3.8/site-packages/nerfacc/cuda/_backend.py", line 73, in <module>
    _C = load(
  File "/xxx/venv/test/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1284, in load
    return _jit_compile(
  File "/xxx/venv/test/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1508, in _jit_compile
    _write_ninja_file_and_build_library(
  File "/xxx/venv/test/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1610, in _write_ninja_file_and_build_library
    _write_ninja_file_to_build_library(
  File "/xxx/venv/test/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 2055, in _write_ninja_file_to_build_library
    _write_ninja_file(
  File "/xxx/venv/test/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 2109, in _write_ninja_file
    assert len(sources) > 0
AssertionError

I have alredy seen the issue #70, but did not solved my problem. Have any idea what could be the problem? Thanks

liruilong940607 commented 1 year ago

hi you can install in using the prebuilt wheels for now. pytorch 1.13.1+cu116 should be compatible with

pip install nerfacc -f https://nerfacc-bucket.s3.us-west-2.amazonaws.com/whl/torch-1.13.0_cu116.html

I'll look into this later

bolopenguin commented 1 year ago

I installed with pip the previous version of Nerfacc: pip install nerfacc==0.3.3 and it works correctly, maybe this can help you. Thank you

machenmusik commented 1 year ago

Note, I ran into the same issue when using latest - on Windows 10 python 3.10 - but reinstalling tag v0.3.4 (df74091) resolved the issue. Perhaps one of the newer commits caused issues?

machenmusik commented 1 year ago

At the moment, the only post-v0.3.4 commit I would expect to alter behavior is https://github.com/KAIR-BAIR/nerfacc/commit/59c88c62663bf8e7357dda1de191edd709e977e4

machenmusik commented 1 year ago

Note that what is installed with nerfacc==0.3.4 requirement causes this issue for me, and does NOT appear to be the same as v0.3.4 tag https://github.com/KAIR-BAIR/nerfacc/commit/df74091cbb0372d17536c230a60dc48cd33127e9 which does not cause this issue.

liruilong940607 commented 1 year ago

Thanks. I suspect it is the PyPI version that I uploaded don't have the cuda code included. This happens after I migrate from pyproject.toml to setup.py. Not sure about the solution yet but might be something around package_date setting

BingHanOfUESTC commented 1 year ago

I had the same problem, which I solved by modifying the init.py file in the nerfacc package. Specifically, in the init.py file, add from .cuda import csrc to the header and csrc to all = []. In this way, the csrc module in the cuda can be found when the from nerfacc import csrc command is executed.

machenmusik commented 1 year ago

I had the same problem, which I solved by modifying the init.py file in the nerfacc package. Specifically, in the init.py file, add from .cuda import csrc to the header and csrc to all = []. In this way, the csrc module in the cuda can be found when the from nerfacc import csrc command is executed.

(@liruilong940607 does this proposed solution seem correct? If so, would be great to correct and bump release.)

liruilong940607 commented 1 year ago

Sorry was occupied by other stuffs.

I just looked into it and got it fixed in https://github.com/KAIR-BAIR/nerfacc/commit/f49a440521c0b034ee6e76a9a2b585d16ae07e86

I'm building the wheels right now and if everything goes fine I should be able to bump it to 0.3.5 on PyPI by the end of today.

machenmusik commented 1 year ago

Thanks! So far so good with the wheel pip install nerfacc -f https://nerfacc-bucket.s3.us-west-2.amazonaws.com/whl/torch-1.13.0_cu117.html

liruilong940607 commented 1 year ago

Close as fixed.

machenmusik commented 1 year ago

Thank you!

ypx19 commented 1 year ago

I installed with pip the previous version of Nerfacc: pip install nerfacc==0.3.3 and it works correctly, maybe this can help you. Thank you

I met the same problem,and your solution worked. My previous version of nerfacc is 0.3.5.

sqirrel3 commented 8 months ago

Hello. I've installed nerfstudio (0.3.4 requires nerfacc==0.5.2),

Requirement already satisfied: nerfacc==0.5.2 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (0.5.2) Requirement already satisfied: rich>=12 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from nerfacc==0.5.2) (13.6.0) Requirement already satisfied: torch in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from nerfacc==0.5.2) (2.0.1+cu118) Requirement already satisfied: markdown-it-py>=2.2.0 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from rich>=12->nerfacc==0.5.2) (2.2.0) Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from rich>=12->nerfacc==0.5.2) (2.16.1) Requirement already satisfied: typing-extensions<5.0,>=4.0.0 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from rich>=12->nerfacc==0.5.2) (4.8.0) Requirement already satisfied: filelock in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from torch->nerfacc==0.5.2) (3.13.1) Requirement already satisfied: sympy in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from torch->nerfacc==0.5.2) (1.12) Requirement already satisfied: networkx in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from torch->nerfacc==0.5.2) (3.1) Requirement already satisfied: jinja2 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from torch->nerfacc==0.5.2) (3.1.2) Requirement already satisfied: mdurl~=0.1 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from markdown-it-py>=2.2.0->rich>=12->nerfacc==0.5.2) (0.1.2) Requirement already satisfied: MarkupSafe>=2.0 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from jinja2->torch->nerfacc==0.5.2) (2.1.3) Requirement already satisfied: mpmath>=0.19 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from sympy->torch->nerfacc==0.5.2) (1.3.0)

but when I run instant-ngp I get this error: Traceback (most recent call last): ImportError: cannot import name 'csrc' from 'nerfacc' (C:\Users\anaconda3\envs\nerfstudio\lib\site-packages\nerfacc__init__.py).

I've also tried older versions of nerfacc, but they are not compatible with the nerfstudio version.

Thank you.

ypx19 commented 5 months ago

I’m sorry , I didn’t find the solution. I would appreciate it If you let me know when you solve the problem . Keep in touch.在 2024年2月10日,09:36,Dinis Martinho @.***> 写道:

Hello. I've installed nerfstudio (0.3.4 requires nerfacc==0.5.2), Requirement already satisfied: nerfacc==0.5.2 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (0.5.2) Requirement already satisfied: rich>=12 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from nerfacc==0.5.2) (13.6.0) Requirement already satisfied: torch in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from nerfacc==0.5.2) (2.0.1+cu118) Requirement already satisfied: markdown-it-py>=2.2.0 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from rich>=12->nerfacc==0.5.2) (2.2.0) Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from rich>=12->nerfacc==0.5.2) (2.16.1) Requirement already satisfied: typing-extensions<5.0,>=4.0.0 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from rich>=12->nerfacc==0.5.2) (4.8.0) Requirement already satisfied: filelock in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from torch->nerfacc==0.5.2) (3.13.1) Requirement already satisfied: sympy in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from torch->nerfacc==0.5.2) (1.12) Requirement already satisfied: networkx in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from torch->nerfacc==0.5.2) (3.1) Requirement already satisfied: jinja2 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from torch->nerfacc==0.5.2) (3.1.2) Requirement already satisfied: mdurl~=0.1 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from markdown-it-py>=2.2.0->rich>=12->nerfacc==0.5.2) (0.1.2) Requirement already satisfied: MarkupSafe>=2.0 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from jinja2->torch->nerfacc==0.5.2) (2.1.3) Requirement already satisfied: mpmath>=0.19 in c:\users\anaconda3\envs\nerfstudio\lib\site-packages (from sympy->torch->nerfacc==0.5.2) (1.3.0) but when I run instant-ngp I get this error: Traceback (most recent call last): ImportError: cannot import name 'csrc' from 'nerfacc' (C:\Users\anaconda3\envs\nerfstudio\lib\site-packages\nerfaccinit.py). I've also tried older versions of nerfacc, but they are not compatible with the nerfstudio version. Thank you.

Have you found the issue yet? I'm in that exact same situation.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

HanTnx commented 4 months ago

PyTorch under Windows 10 reports an error UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the specified file.

Solution: This error is due to the fact that the vc environment is not configured in the environment variables, so you only need to configure the environment. First, you need to download any version of VS20xx. It is recommended to directly search for the cl.exe file in the C:\Program Files (x86)\Microsoft Visual Studio path and find the directory. Because my system is 64-bit, I have to choose 64-bit. If you are 32-bit, Just choose X86.

Like my cl.exe path is "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64"

Add the path into System Properties >>>Environments Variables >> Path (Edit Environment Variables)