Problem loading C++ torch script oeprator from python

Hi folks,

following the tutorial at 1, I am trying to implement a simple C++ torch script operator. I’ve installed libtorch 2 and managed to compile my module. However, when I am trying to load the operator via

import torch

this is the error I am getting:

$ python2 ../test/ 
Traceback (most recent call last):
  File "../test/", line 2, in <module>
  File "/home/jviereck/.local/lib/python2.7/site-packages/torch/", line 102, in load_library
  File "/usr/lib/python2.7/ctypes/", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/jviereck/dev/tools/torch_pinocchio/build/ undefined symbol: _ZN6caffe26detail37_typeMetaDataInstance_preallocated_29E

Note that I’ve installed the torch via pip install torch.

My best guess is that the python torch is not aware about the libraries in the libtorch folder. Does someone has an idea how to resolve this?


Not sure if that’s related to your problem, but similar issues originated in multiple PyTorch installatons (or some old, unused installs).
Could you check, if your current environment has some old PyTorch installs (in conda, pip, and build from source)?

My guess is that either

  • Your compiler version is not the same as the one that compiled the caffe2 library, in particular differing in its name mangling (mapping C++ namespace+symbol+signature to a unique name in an address table)
  • The function you were using somewhere in your extension (caffe2::typeMetaDataInstance_preallocated) is not exported by the libraries you linked against.

What you can do is check whether you are getting the same error when compiling with the same compiler as was used to compile Caffe2.