0

I'm trying to install Facebook's fasttext Python bindings on Mac OSX 10.12 Sierra using pip. I'm getting the following error while running sudo pip install fasttext:

Collecting fasttext
  Downloading fasttext-0.8.2.tar.gz (73kB)
    100% |████████████████████████████████| 81kB 1.9MB/s 
Requirement already satisfied: numpy>=1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy-1.12.0rc2-py2.7-macosx-10.6-intel.egg (from fasttext)
Requirement already satisfied: future in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from fasttext)
Installing collected packages: fasttext
  Running setup.py install for fasttext ... error
    Complete output from command /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-sxrbh9/fasttext/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-2vHzji-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.6-intel-2.7
    creating build/lib.macosx-10.6-intel-2.7/fasttext
    copying fasttext/__init__.py -> build/lib.macosx-10.6-intel-2.7/fasttext
    copying fasttext/model.py -> build/lib.macosx-10.6-intel-2.7/fasttext
    running build_ext
    building '*' extension
    creating build/temp.macosx-10.6-intel-2.7
    creating build/temp.macosx-10.6-intel-2.7/fasttext
    creating build/temp.macosx-10.6-intel-2.7/fasttext/cpp
    creating build/temp.macosx-10.6-intel-2.7/fasttext/cpp/src
    /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c fasttext/fasttext.c -o build/temp.macosx-10.6-intel-2.7/fasttext/fasttext.o -O3 -pthread -funroll-loops -std=c++0x -stdlib=libc++ -mmacosx-version-min=10.7
    clang: error: no such file or directory: 'fasttext/fasttext.c'
    clang: error: no input files
    error: command '/usr/bin/clang' failed with exit status 1

    ----------------------------------------

To examine the package, I run sudo pip install fasttext --no-clean to keep the temporary package directory. I look into it and see that there is actually no fasttext/fasttext.c file, although there is fasttext/fasttext.cpp file. If I manually run the building command with fasttext.c replaced by fasttext.cpp, it seems to complete successfully.

/usr/bin/clang <...> -c fasttext/fasttext.cpp <...>

But now, to actually install the package, I want to tell setup.py to use fasttext.cpp instead of fasttext.c. And this is something I don't know how to do. Greping the folder does not find any explicit mentions of fasttext.c, so I assume it's taken implicitly by some rule I'm not aware of. Here is full setup.py file contents:

from setuptools import setup, find_packages
from setuptools.extension import Extension
from Cython.Build import cythonize
from sys import platform
import unittest

# Define the C++ extension
if platform == "darwin":
    extra_compile_args = ['-O3', '-pthread', '-funroll-loops', '-std=c++0x', '-stdlib=libc++', '-mmacosx-version-min=10.7']
else:
    extra_compile_args = ['-O3', '-pthread', '-funroll-loops', '-std=c++0x']

extensions = [
    Extension('*',
        sources=[
            'fasttext/fasttext.pyx',
            'fasttext/interface.cc',
            'fasttext/cpp/src/args.cc',
            'fasttext/cpp/src/dictionary.cc',
            'fasttext/cpp/src/matrix.cc',
            'fasttext/cpp/src/model.cc',
            'fasttext/cpp/src/utils.cc',
            'fasttext/cpp/src/fasttext.cc',
            'fasttext/cpp/src/vector.cc',
            'fasttext/cpp/src/main.cc'
        ],
        language='c++',
        extra_compile_args=extra_compile_args)
]

# Package details
setup(
    name='fasttext',
    version='0.8.2',
    author='Bayu Aldi Yansyah',
    author_email='[email protected]',
    url='https://github.com/pyk/fastText.py',
    description='A Python interface for Facebook fastText library',
    long_description=open('README.rst', 'r').read(),
    license='BSD 3-Clause License',
    packages=['fasttext'],
    ext_modules = cythonize(extensions),
    install_requires=[
        'numpy>=1',
        'future'
    ],
    classifiers= [
        'Development Status :: 2 - Pre-Alpha',
        'Intended Audience :: Developers',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: BSD License',
        'Programming Language :: C++',
        'Programming Language :: Cython',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Topic :: Scientific/Engineering :: Artificial Intelligence'
    ]
)

So could you help me to install the package?

1 Answer 1

0

Wow, surprisingly after hours of digging, a simple update of distutils from version 0.6.14 to 0.7.3 solved the problem:

sudo pip install -U distribute

For what it's worth, this idea came to my mind after I ran

DISTUTILS_DEBUG=1 python setup.py build 

to see exactly what's going on during build process, and then decided to update all libraries involved.

1
  • And it happened minutes after I posted the question, so StackExchange power is with us, even silently. Commented Jan 4, 2017 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .