Error importing torch

I installed PyTorch from source using the latest githu repo. When I tryied to import torch, I get the following

lex@lex:~/Documents/NNs/pytorch$ python -c "import torch"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "torch/__init__.py", line 53, in <module>
    from torch._C import *
ImportError: No module named _C

There is a _C.so module in the /usr/local/lib/python2.7/dist-packages/torch/ path. DOes anyone know why this is giving me this error?

change your directory. Dont run this command from pytorch root directory.

1 Like

I never did. It always gives that error when I install from source. I have noticed that conda installs don’t do this. I wonder why this is so.

lex@lex:~/Documents$ /usr/bin/python -c "import torch"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/torch/__init__.py", line 53, in <module>
    from torch._C import *
ImportError: /usr/local/lib/python2.7/dist-packages/torch/lib/libgomp.so.1: version `GOMP_4.0' not found (required by /usr/local/lib/python2.7/dist-packages/torch/lib/libTH.so.1)
lex@lex:~/Documents$ 

Found a related issue here

I had a similar issue. Installing with sudo (source install) solved it for me.

Here is a working solution for this problem when you install from source from varunagrawal:

"
I recently encountered this exact problem when compiling from source. A clean install also didn’t help. What worked was removing the libgomp.so.1 library from the torch directory and instead sym-linking it to the one in /usr/lib.

ln -s /usr/lib/libgomp.so.1 path/to/python/site-packages/torch/lib/libgomp.so.1

"

update your numpy using
pip install numpy --upgrade
it works for me