Error libtorch_python.so: cannot open shared object file: No such file or directory

12,932

My problem is solved. I'm uninstalling my torch twice

pip uninstall torch
pip uninstall torch

and then re-installing it back:

pip install torch==1.0.1.post2
Share:
12,932
Andira Gita
Author by

Andira Gita

Updated on June 26, 2022

Comments

  • Andira Gita
    Andira Gita almost 2 years

    I'm trying to implement fastai pretrain language model and it requires torch to work. After run the code, I got some problem about the import torch._C

    I run it on my linux, python 3.7.1, via pip: torch 1.0.1.post2, cuda V7.5.17. I'm getting this error:

    Traceback (most recent call last):
      File "pretrain_lm.py", line 7, in <module>
        import fastai
      File "/home/andira/anaconda3/lib/python3.7/site-packages/fastai/__init__.py", line 1, in <module>
        from .basic_train import *
      File "/home/andira/anaconda3/lib/python3.7/site-packages/fastai/basic_train.py", line 2, in <module>
        from .torch_core import *
      File "/home/andira/anaconda3/lib/python3.7/site-packages/fastai/torch_core.py", line 2, in <module>
        from .imports.torch import *
      File "/home/andira/anaconda3/lib/python3.7/site-packages/fastai/imports/__init__.py", line 2, in <module>
        from .torch import *
      File "/home/andira/anaconda3/lib/python3.7/site-packages/fastai/imports/torch.py", line 1, in <module>
        import torch, torch.nn.functional as F
      File "/home/andira/anaconda3/lib/python3.7/site-packages/torch/__init__.py", line 84, in <module>
        from torch._C import *
    ImportError: libtorch_python.so: cannot open shared object file: No such file or directory
    

    So I tried to run this line:

    from torch._C import *
    

    and got same result

    ImportError: libtorch_python.so: cannot open shared object file: No such file or directory
    

    I checked /home/andira/anaconda3/lib/python3.7/site-packages/torch/lib and there are only libcaffe2_gpu.so and libshm.so file, and I can't find libtorch_python.so either. My question is, what is actually libtorch_python.so? I've read some of article and like most of it talked about undefined symbol, not cannot open shared object file: No such file or directory like mine. I'm new at python and torch so I really appreciate your answer.

  • Ekho
    Ekho over 4 years
    I have been using TensorFlow for a while, but after the release of Detectron2, by FAIR, I decided to give it a go and also start getting my hands dirty with PyTorch. Very upsetting to find the same issue as you did and even more upset with the way it was fixed. Anyways, thanks for posting.
  • Abu Shoeb
    Abu Shoeb over 3 years
    This is a lifesaver 🤓