Pytorch3d: Import error (missing symbol) on MacOS

Created on 6 Jan 2021  ·  6Comments  ·  Source: facebookresearch/pytorch3d

🐛 Bugs / Unexpected behaviors

I installed PyTorch3D on a fresh installation on MacOS (there was no PyTorch installation). PyTorch 1.7.1 was automatically installed by PyTorch3D as a dependency. When trying to import PyTorch3D, I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/classner/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pytorch3d/io/__init__.py", line 4, in <module>
    from .obj_io import load_obj, load_objs_as_meshes, save_obj
  File "/Users/classner/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pytorch3d/io/obj_io.py", line 14, in <module>
    from pytorch3d.renderer import TexturesAtlas, TexturesUV
  File "/Users/classner/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pytorch3d/renderer/__init__.py", line 3, in <module>
    from .blending import (
  File "/Users/classner/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pytorch3d/renderer/blending.py", line 9, in <module>
    from pytorch3d import _C
ImportError: dlopen(/Users/classner/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pytorch3d/_C.cpython-37m-darwin.so, 2): Symbol not found: __ZN3c104impl23ExcludeDispatchKeyGuardC1ENS_11DispatchKeyE

This is very similar to #377, however I believe that PyTorch3D should pull in the correct version of PyTorch.

No changes were made to the code, I simply used pip install pytorch3d in a fresh Python 3.7.4 environment.

installation

Most helpful comment

Re __init__.py: yes, this is a good idea. We would write the wanted version number on build, probably in a file next to __init__.py. We'd probably have an environment variable which allows the check to be bypassed as well, so that (1) people can live dangerously and (2) people can run setup.py which needs the pytorch3d version number, even when the versions don't match. setup.py would probably set the variable.


For pip install, the version of PyTorch required is only in the specific section.


Is there a resource somewhere stating for which version of PyTorch3D which version of PyTorch is required?

Not unified. The information is in INSTALL.md at the tag you are interested in.

All 6 comments

The cause of the error, as you realise, is the same as #377. The released packages for PyTorch3D on PyPI still require you to already have installed pytorch 1.6.0. The installation is pulling in the wrong version of PyTorch.

We don't fix the version of PyTorch in the metadata of the PyTorch3D wheel, because on Linux this would be really complicated - you need to have the right version of cuda, and that means the version string of PyTorch differs depending on how PyTorch is installed. Even with the right version dependency, the wheel might not be on PyPI anyway but hosted elsewhere, so pip can't install it automatically. However on Mac the situation is simple, PyTorch wheels live in PyPI, and we could make this work by fixing the PyTorch3D wheel's metadata.

@bottler thank you! Do we mention this explicitly in the installation instructions somewhere? Or do we print a warning when trying to install via pip? What would be the best way to let users know of this?

INSTALL.md mentions the need for a specific version of PyTorch.
It might be possible to make the error message friendlier, by writing the torch version into a file next to _C when we build, and checking it every time we import _C.
There's no code which runs at wheel installation time (according to https://realpython.com/python-wheels/#advantages-of-python-wheels etc) so I don't think there's a possibility to print a warning.

At least for mac we should be able to make things "just work" with version numbering.

Thanks for confirming!
Another transparent way would be to remove PyTorch from the automatic dependency list across all platforms, state the version of PyTorch that is required for the version of PyTorch3D. Even more, it's possible to add some lines to the top-level __init__.py of PyTorch3D to

try:
    import pytorch
    # Check pytorch version is correct for PyTorch3D.
    if pytorch.__version__ != 'xyz':
        raise Exception("This version of PyTorch3D needs PyTorch X.Y.Z installed.")
except ImportError:
    raise Exception(" This version of PyTorch3D needs PyTorch X.Y.Z installed.")

This could actually be done in any case and would be transparent and simple.

Even more, INSTALL.md does not provide the specific version of PyTorch required for a specific version of PyTorch3D at a glance. I see the line saying that PyTorch 1.4, 1.5.0, 1.5.1, 1.6.0, or 1.7.0 is required, but which one is it? Is there a resource somewhere stating for which version of PyTorch3D which version of PyTorch is required?

Re __init__.py: yes, this is a good idea. We would write the wanted version number on build, probably in a file next to __init__.py. We'd probably have an environment variable which allows the check to be bypassed as well, so that (1) people can live dangerously and (2) people can run setup.py which needs the pytorch3d version number, even when the versions don't match. setup.py would probably set the variable.


For pip install, the version of PyTorch required is only in the specific section.


Is there a resource somewhere stating for which version of PyTorch3D which version of PyTorch is required?

Not unified. The information is in INSTALL.md at the tag you are interested in.

Was this page helpful?
0 / 5 - 0 ratings