~ ~ ~

Installing FastText on an M1 Mac

# May 5, 2022

We rely on FastText in some of our NLP microservices. Since upgrading to an M1 Macbook, these dependencies have failed to build wheels.

Collecting fasttext
  Using cached fasttext-0.9.2.tar.gz (68 kB)
  Preparing metadata (setup.py) ... done
Collecting pybind11>=2.2
  Using cached pybind11-2.9.2-py2.py3-none-any.whl (213 kB)
Requirement already satisfied: setuptools>=0.7.0 in /Users/piercefreeman/.virtualenvs/myenv/lib/python3.10/site-packages (from fasttext) (62.0.0)
Collecting numpy
  Using cached numpy-1.22.3-cp310-cp310-macosx_11_0_arm64.whl (12.8 MB)
Building wheels for collected packages: fasttext
  Building wheel for fasttext (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.


      src/autotune.cc:25:14: note: expanded from macro 'LOG_VAL_NAN'
          if (std::isnan(val)) {                          
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:165:5: note: expanded from macro 'isnan'
          ( sizeof(x) == sizeof(float)  ? __inline_isnanf((float)(x))          
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for fasttext

After some digging, the default C headers that are shipping with XCode are causing a definition conflict. Removing them fixes the problem. We move these to a temporary folder so we can restore them later, since they are functional for most of the other clang system installs.

sudo mv /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include_tmp

pip install fasttext

sudo mv /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include_tmp /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

And we have a successful install:

Successfully built fasttext
Installing collected packages: pybind11, numpy, fasttext

Stay in Touch

I write mostly about engineering, machine learning, and company building. If you want to get updated about longer essays, subscribe here.

I hate spam so I keep these infrequent - once or twice a month, maximum.