Jimi13 ABC
Jimi13 ABC

Reputation: 19

Trying to install spaCy on M2 Mac using pip:

!pip install cython 
!pip install cymem
!pip install murmurhash
!pip install preshed
!pip install numpy
!pip install blis
!pip install thinc
!pip install 'spacy[apple]'
!pip install -U pip setuptools wheel

all of the above code works.

But when I try to run the code below

!python -m spacy download en_core_web_sm

I get the following error and hence am unable to import spacy :

Traceback (most recent call last):
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/site-packages/spacy/__init__.py", line 6, in <module>
    from .errors import setup_default_warnings
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/site-packages/spacy/errors.py", line 2, in <module>
    from .compat import Literal
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/site-packages/spacy/compat.py", line 38, in <module>
    from thinc.api import Optimizer  # noqa: F401
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/site-packages/thinc/api.py", line 2, in <module>
    from .initializers import normal_init, uniform_init, glorot_uniform_init, zero_init
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/site-packages/thinc/initializers.py", line 4, in <module>
    from .backends import Ops
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/site-packages/thinc/backends/__init__.py", line 10, in <module>
    from .mps_ops import MPSOps
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/site-packages/thinc/backends/mps_ops.py", line 14, in <module>
    from thinc_apple_ops import AppleOps
  File "/Users/kyrshanlyngdoh/opt/anaconda3/lib/python3.9/site-packages/thinc_apple_ops/__init__.py", line 1, in <module>
    from .ops import AppleOps
  File "thinc_apple_ops/ops.pyx", line 1, in init thinc_apple_ops.ops
  File "thinc_apple_ops/blas.pyx", line 1, in init thinc_apple_ops.blas
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

Upvotes: 2

Views: 1900

Answers (1)

aab
aab

Reputation: 11484

In a new venv, try this:

pip install -U pip setuptools wheel
pip install 'spacy[apple]' --only-binary spacy,thinc,blis,thinc-apple-ops --no-cache-dir

If this works, you may want to clear your pip cache to remove incompatible cached wheels that may have been compiled from source in the past (pip cache purge) and then a simple pip install 'spacy[apple]' should work again. (There's no need to install the other dependencies individually.)

Upvotes: 1

Related Questions