[Resolved] Pytorch v0.2 OSX issue

I just upgraded to v0.2 with pip install http://download.pytorch.org/whl/torch-0.2.0.post1-cp27-none-macosx_10_7_x86_64.whl and pip install torchvision. When I try importing torch in the shell, I get:

>>> import torch
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/__init__.py", line 53, in <module>
    from torch._C import *
ImportError: numpy.core.multiarray failed to import

I already have numpy and can do

>>> import numpy as np
>>> np.empty(3)
array([ 0.,  0.,  2.])
>>> 

But cannot use Pytorch…

Had same issue. I uninstalled and reinstalled numpy than installed torch again. That fixed for me

pip install --upgrade numpy will solve it.

3 Likes

Thanks! That solved it!

This does not solve it for me:

import numpy as np
np.__version__

'1.11.2'

import torch 

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-21195f21f05e> in <module>()
----> 1 import torch

/home/twenty/anaconda3/envs/mp/lib/python3.5/site-packages/torch/__init__.py in <module>()
     51 sys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_NOW)
     52 
---> 53 from torch._C import *
     54 
     55 __all__ += [name for name in dir(_C)

ImportError: numpy.core.multiarray failed to import

I have the same issue.

>>> import numpy as np
>>> np.__version__
'1.12.1'
>>> import torch
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/odin/miniconda3/lib/python3.5/site-packages/torch/__init__.py", line 53, in 
<module>
    from torch._C import *
ImportError: numpy.core.multiarray failed to import

reinstall does not help

1 Like

Thanks a lot, it fixed my problem too.