Reputation: 351
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.
Upvotes: 9
Views: 38833
Reputation: 1674
I run into this error when I accidentally overwrite pytorch
with a different channel. My original pytorch
installation is from pytorch
channel and in a later update it was overwritten with the one from conda-forge
. I got this error even if the version is the same. After reinstalling pytorch
from pytorch
channel, the error is gone.
Upvotes: 0
Reputation: 15659
Try to use pytorch
1.4.0. For which, upgrade the pytorch
library using the following command,
pip install -U torch==1.5
If you are working on Colab then use the following command,
!pip install -U torch==1.5
Still facing challenges on the library then install detectron2
library also.
!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html
Upvotes: -1
Reputation: 351
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
Upvotes: 11