Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Undefined symbol FreeCudaMemoryCallbacksRegistry

📅 2020-Mar-04 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive


I installed PyTorch on my system and the very first import failed with this error:

>>> import torch
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    import torch
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/", line 251, in load_module
    module = self.loader.load_module(name)
  File "/home/joe/.local/lib/python3.6/site-packages/torch/", line 81, in <module>
    from torch._C import *
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/", line 251, in load_module
    module = self.loader.load_module(name)
ImportError: /home/joe/.local/lib/python3.6/site-packages/torch/lib/ undefined symbol: _ZN3c1031FreeCudaMemoryCallbacksRegistryEv


It was obvious that the problem was CUDA or PyTorch's interface to CUDA.

I checked that /usr/local/cuda symlink was pointing to my CUDA 10.1 installation. I also made sure that /usr/local/cuda/lib64 was in my LD_LIBRARY_PATH. However, this did not fix the problem.

I then started checking which libraries /home/joe/.local/lib/python3.6/site-packages/torch/lib/ was dynamically loading at runtime using the ldd command. This investigation revealed that all the dependent libraries were in /home/joe/.local/lib/python3.6/site-packages, except for one: /usr/local/lib/ Turns out that this is a library installed by PyTorch and I had no idea why there was an old copy of this file in /usr/local/lib. It was probably from an old Ubuntu installation of PyTorch that did not uninstall properly.

I removed this file and PyTorch picked up its local and everything was fine!