Cannot import pytorch on wsl2

Hello,
I’m trying to use pytorch from inside my wsl2 python installation (details below)

>python --version                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
Python 3.9.7 


> conda list | grep -i torch                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
cpuonly                   2.0                           0    pytorch                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
pytorch                   1.10.0              py3.9_cpu_0    pytorch                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
pytorch-mutex             1.0                         cpu    pytorch    

This is the error I get when I try to import torch:

In [1]: import torch                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  

----------------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <ipython-input-1-eb42ca6e4af3> in <module>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ----> 1 import torch                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ~/software/anaconda3/lib/python3.9/site-packages/torch/__init__.py in <module>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         194     # See Note [Global dependencies]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
195     if USE_GLOBAL_DEPS:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
--> 196         _load_global_deps()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
197     from torch._C import *  # noqa: F403                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
198                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
~/software/anaconda3/lib/python3.9/site-packages/torch/__init__.py in _load_global_deps()                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
147     lib_path = os.path.join(os.path.dirname(here), 'lib', lib_name)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
148                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
--> 149     ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
150                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
151                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
~/software/anaconda3/lib/python3.9/ctypes/__init__.py in __init__(self, name, mode, handle, 
use_errno, use_last_error, winmode)                                                                                                                                                                                                                                                                                                                                                                                                                                         
380                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
381         if handle is None:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
--> 382             self._handle = _dlopen(self._name, mode)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
383         else:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
384             self._handle = handle                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
OSError: /home/fj/software/anaconda3/lib/python3.9/site-
packages/torch/lib/../../../../libmkl_gnu_thread.so: unexpected reloc type 0x00000907       

Any pointers/links to what the issue might be would be appreciated.

Thanks

1 Like