tatsy/torchmcubes

Build fails with `No module named 'torch'` (solution)

Closed this issue ยท 9 comments

Hi, and thanks for the implementation!

Just wanted to let other users know about a build problem.

My default Python is python3.7. The installation fails because pip is trying to invoke python instead:

$ python3.7 -m pip install .

  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3.7 /home/shrubb/.local/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpjpnon38i
       cwd: /home/shrubb/Projects/mcubes_pytorch
  Complete output (18 lines):
  Traceback (most recent call last):
    File "/home/shrubb/.local/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 280, in <module>
      main()
    File "/home/shrubb/.local/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/home/shrubb/.local/lib/python3.7/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 114, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/tmp/pip-build-env-2ine7t9t/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 155, in get_requires_for_build_wheel
      config_settings, requirements=['wheel'])
    File "/tmp/pip-build-env-2ine7t9t/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 135, in _get_build_requires
      self.run_setup()
    File "/tmp/pip-build-env-2ine7t9t/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 259, in run_setup
      self).run_setup(setup_script=setup_script)
    File "/tmp/pip-build-env-2ine7t9t/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 150, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 2, in <module>
      from torch.utils.cpp_extension import BuildExtension
  ModuleNotFoundError: No module named 'torch'
  ----------------------------------------

The solution is to delete (or move or rename) pyproject.toml.

tatsy commented

Hi @shrubb,

This is a problem of a newer Pip. When pyproject.toml exists, the newer Pip builds the scripts differently (PEP 517).

To disable this, add a flag --no-use-pep517 to Pip.

Hope this helps!

tatsy commented

To avoid any misunderstanding, I removed pyproject.toml.
Now you can simpy install the module by:

pip install git+https://github.com/tatsy/torchmcubes.git

Hi there,
Just hit this issue, seems to still be alive.
Trying to install TripoSR on windows 10

image

Hi @shodanx2, I do not think this is the problem of this repo. Please consult the owner of TripoSR. If you cannot install this repo directly with pip to your enviroment (i.e., run "pip install git+https://github.com/tatsy/torchmcubes.git" directly), then, please let me know with the errors you received.

Hi,

Still digging through this. I have a fresh python install, I suspect all people trying out TripoSR will hit the same roadblock here.
It's an image-to-3d model that just came out yesterday.

I'm not sure I'm still in the TripoSR setup proper, it fails installing the requirements

Found similar issue

facebookresearch/xformers#740

I tried after a restart, to just install torchmcubes alone, using the command suggested above

pip install git+https://github.com/tatsy/torchmcubes.git

image

I tried --no-use-pep517, got

--no-use-pep517 error: It is not possible to use --no-use-pep517
without setuptools and wheel installed.

So far I installed python from https://www.python.org/ftp/python/3.12.2/python-3.12.2-amd64.exe

then ran

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install --upgrade setuptools
pip install -r requirements.txt

So there isn't much room for errors...

There in particular

_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])

The other thread says "install wheel

Progress, the error has changed

image

"we could not find ninja"

New error, progress !

image

"error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/"

Ok installing https://download.visualstudio.microsoft.com/download/pr/5e7b923b-7d89-4e14-95b8-a84ab168e243/5b539dc7ab1e94494083793fe65c41a6b0fe3b1cdeb38ddd9d04c151c3c2fcf0/vs_BuildTools.exe

Oh I bet that is going to re-activate windows update and wreck my system :( oh well, yolo, windows re-install after this !

image

Installed but still getting the same error.

So I'm hitting post here and restarting the computer.

Ok,

Still did not work, had another look at the MS build tools

image

This is not enough
It needs Visual Studio Community plus the "workload" Desktop C++

image

Now it builds

image

TripoSR-main>pip install -r requirements.txt gets pasts torchmcubes !

image

installed rust package manager https://win.rustup.rs/x86_64

and requirements finishes

image

total success

image

So recap, for anyone ending up here from TripoSR

here are your steps for a fresh windows 10 install

install python https://www.python.org/ftp/python/3.12.2/python-3.12.2-amd64.exe
install MS Visual C++ at https://visualstudio.microsoft.com/visual-cpp-build-tools/
choose Visual Studio community  and Desktop C++ and build tools
Install rust package manager from https://win.rustup.rs/x86_64
download TripoSR https://github.com/VAST-AI-Research/TripoSR/archive/refs/heads/main.zip
uncompress tar -xf TripoSR-main.zip
restart your terminal and maybe reboot here
install torch with   pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
run the following
pip install --upgrade setuptools
pip install wheel
pip install ninja
pip install -r requirements.txt

and then magic !

python run.py examples/chair.png --output-dir output/

error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools":

From my understanding, maybe the problem is your Python version. As 3.12 is a bit rather new, maybe the correct combination of Python 3.12 and PyTorch, TorchVision, and CUDAToolkit cannot be found.

So, I think downgrading your Python to 3.9 or 3.10 may resolve the problem. Cheers.

I have this issue as well on 3.9. Basically everything else the same.
`--> RUN --mount=target=requirements.txt,source=requirements.txt pip install --no-cache-dir -r requirements.txt
Collecting git+https://github.com/tatsy/torchmcubes.git (from -r requirements.txt (line 16))
Cloning https://github.com/tatsy/torchmcubes.git to /tmp/pip-req-build-ia4y_d13
Running command git clone --filter=blob:none --quiet https://github.com/tatsy/torchmcubes.git /tmp/pip-req-build-ia4y_d13
Resolved https://github.com/tatsy/torchmcubes.git to commit 3aef8af
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'error'
error: subprocess-exited-with-error

ร— python setup.py egg_info did not run successfully.
โ”‚ exit code: 1
โ•ฐโ”€> [6 lines of output]
Traceback (most recent call last):
File "", line 2, in
File "", line 34, in
File "/tmp/pip-req-build-ia4y_d13/setup.py", line 2, in
from torch.utils.cpp_extension import BuildExtension
ModuleNotFoundError: No module named 'torch'
[end of output]`

Ok,

Still did not work, had another look at the MS build tools

image

This is not enough It needs Visual Studio Community plus the "workload" Desktop C++

image

Now it builds

image

TripoSR-main>pip install -r requirements.txt gets pasts torchmcubes !

image

installed rust package manager https://win.rustup.rs/x86_64

and requirements finishes

image

total success

image

So recap, for anyone ending up here from TripoSR

here are your steps for a fresh windows 10 install

install python https://www.python.org/ftp/python/3.12.2/python-3.12.2-amd64.exe
install MS Visual C++ at https://visualstudio.microsoft.com/visual-cpp-build-tools/
choose Visual Studio community  and Desktop C++ and build tools
Install rust package manager from https://win.rustup.rs/x86_64
download TripoSR https://github.com/VAST-AI-Research/TripoSR/archive/refs/heads/main.zip
uncompress tar -xf TripoSR-main.zip
restart your terminal and maybe reboot here
install torch with   pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
run the following
pip install --upgrade setuptools
pip install wheel
pip install ninja
pip install -r requirements.txt

and then magic !

python run.py examples/chair.png --output-dir output/

error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools":

thx my friend,"install wheel" solved my problem ,too. :)