Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests failing ImportError: cannot import name '_C' from 'pytorch3d' #1664

Closed
jmjava opened this issue Oct 20, 2023 · 6 comments
Closed

Comments

@jmjava
Copy link

jmjava commented Oct 20, 2023

Following the install instructions when I get to python setup.py install I end up with this. I had downloaded ninja and added it to my path, without ninja a don't get as far it quit earlier

C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.37.32822/include\crtdefs.h(10): fatal error C1083: Cannot open include file: 'corecrt.h': No such file or directory
marching_cubes.cu

@jmjava
Copy link
Author

jmjava commented Oct 21, 2023

I ended up reinstalling everything and making to sure to include the necessary components in the VS build tools installer. It seems to be working on my Windows 10 machine. Also removed ninja from path

windows 10 SDK
Cuda 11.8
Vsstudio build tools for VS19
Universal CRT SDK
x64 build tools for c++

@jmjava jmjava closed this as completed Oct 21, 2023
@jmjava
Copy link
Author

jmjava commented Oct 21, 2023

It appear the unit tests are failing now:

python3 -m unittest discover -v -s tests -t .

ERROR: tests.test_vis (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_vis
Traceback (most recent call last):
  File "C:\Users\User\anaconda3\envs\pytorch3d\lib\unittest\loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "C:\Users\User\anaconda3\envs\pytorch3d\lib\unittest\loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "C:\Users\User\pythorch3d\tests\test_vis.py", line 10, in <module>
    from pytorch3d.renderer import HeterogeneousRayBundle, PerspectiveCameras, RayBundle
  File "C:\Users\User\pythorch3d\pytorch3d\renderer\__init__.py", line 7, in <module>
    from .blending import (
  File "C:\Users\User\pythorch3d\pytorch3d\renderer\blending.py", line 10, in <module>
    from pytorch3d import _C
ImportError: cannot import name '_C' from 'pytorch3d' (C:\Users\User\pythorch3d\pytorch3d\__init__.py)

install.log

@jmjava jmjava reopened this Oct 21, 2023
@jmjava jmjava changed the title Cannot open include file: 'corecrt.h': No such file or directory Unit tests failing ImportError: cannot import name '_C' from 'pytorch3d' (C:\Users\User\pythorch3d\pytorch3d\__init__.py) Oct 21, 2023
@jmjava jmjava changed the title Unit tests failing ImportError: cannot import name '_C' from 'pytorch3d' (C:\Users\User\pythorch3d\pytorch3d\__init__.py) Unit tests failing ImportError: cannot import name '_C' from 'pytorch3d' Oct 21, 2023
@jmjava
Copy link
Author

jmjava commented Oct 22, 2023

moved to python 3.10 and upgraded pytorch less errors in unit tests but still same cannot import issue

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

@bottler
Copy link
Contributor

bottler commented Oct 23, 2023

I think the problem here may be a gotcha with paths. Are you installing with -e/--editable on pip install? I think you might not be. That means there are two separate directories containing the pytorch3d code: the one in your checkout (i.e. C:\Users\User\pythorch3d\pytorch3d\), and the one which is installed (probably "C:\Users\User\anaconda3\envs\pytorch3d\lib\python3.10\site-packages\pytorch3d") and only the second one is a proper install with the _C DLL file. Because you are running the tests from C:\Users\User\pythorch3d, imports of pytorch3d are looking at the local one.

To test this theory, can you try moving to another directory and starting python and running from pytorch3d.renderer import HeterogeneousRayBundle, PerspectiveCameras, RayBundle, which I expect to work. In this case pytorch3d is installed correctly but is unusable from the source directory. To run the tests, you could temporarily rename the folder C:\Users\User\pythorch3d\pytorch3d to something else. To avoid this problem for future installs, I recommend using pip install -e.

If this theory is wrong and the installation of pytorch3d definitely succeeded, then you probably have a file called _C<something>.dll in C:\Users\User\pythorch3d\pytorch3d which python does not like for some reason. If so, I suggest opening that file in dependency walker or a debugger and sharing any interesting errors from that here.

@ofdengdeng
Copy link

i met the same problem,have you already solve it?

@bottler
Copy link
Contributor

bottler commented Dec 30, 2024

@ofdengdeng please open a new issue with details of your setup if you still need help. This one is stale.

@bottler bottler closed this as completed Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants