如何配置python setup.py使用的源文件(安装fasttext)

如何配置python setup.py使用的源文件(安装fasttext)

我正在尝试安装Facebook 的 fasttext Python 绑定在 Mac OSX 10.12 Sierra 上使用 pip。运行时出现以下错误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

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

为了检查包,我运行sudo pip install fasttext --no-clean以保留临时包目录。我查看它并发现实际上没有fasttext/fasttext.c文件,尽管有fasttext/fasttext.cpp文件。如果我手动运行构建命令并将fasttext.c其替换为fasttext.cpp,它似乎成功完成。

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

但是现在,要实际安装包,我想告诉setup.py使用fasttext.cpp而不是fasttext.c。这是我不知道该怎么做的事情。Grep在文件夹中找不到任何明确提及fasttext.c,因此我认为它是被某些我不知道的规则隐式地采用的。以下是完整的setup.py文件内容:

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'
    ]
)

那么你能帮我安装这个软件包吗?

答案1

哇,令人惊讶的是,经过几个小时的挖掘,从版本 0.6.14 到 0.7.3 的简单更新distutils解决了这个问题:

sudo pip install -U distribute

不管怎样,这个想法是在我跑步后产生的

DISTUTILS_DEBUG=1 python setup.py build 

准确了解构建过程中发生的情况,然后决定更新所有涉及的库。

相关内容