Search code examples
pythonpippytorchtorchpython-3.7

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


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.


Solution

  • 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