无法安装OpenFST Python扩展

时间:2018-06-25 17:32:43

标签: python openfst

我正在尝试根据this指南安装OpenFST Python扩展。有两种方法可以执行此操作。
第一种选择是在配置OpenFst的过程中发出--enable-python,但我尝试并失败了。
所以我选择了第二个选项。我使用以下命令成功安装了OpenFST:

./configure --enable-far
make
sudo make install

然后我尝试使用openfst安装PyPi软件包pip
pip install openfst
并出现以下错误:

Collecting openfst
  Using cached https://files.pythonhosted.org/packages/cc/6b/cc05392480e2232e176be895b9ca2b9f4a5f153f99ab276b37d440b3bace/openfst-1.6.6.tar.gz
Building wheels for collected packages: openfst
  Running setup.py bdist_wheel for openfst ... error
  Complete output from command /home/arif/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-7y6dl6o2/openfst/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-zadciiwk --python-tag cp36:
  running bdist_wheel
  running build
  running build_ext
  building 'pywrapfst' extension
  creating build
  creating build/temp.linux-x86_64-3.6
  gcc -pthread -B /home/arif/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/arif/anaconda3/include/python3.6m -c pywrapfst.cc -o build/temp.linux-x86_64-3.6/pywrapfst.o -std=c++11 -Wno-unneeded-internal-declaration -Wno-unused-function
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  pywrapfst.cc:557:40: fatal error: fst/extensions/far/getters.h: No such file or directory
  compilation terminated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for openfst
  Running setup.py clean for openfst
Failed to build openfst
Installing collected packages: openfst
  Running setup.py install for openfst ... error
    Complete output from command /home/arif/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-7y6dl6o2/openfst/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-record-3niypfz6/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'pywrapfst' extension
    creating build
    creating build/temp.linux-x86_64-3.6
    gcc -pthread -B /home/arif/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/arif/anaconda3/include/python3.6m -c pywrapfst.cc -o build/temp.linux-x86_64-3.6/pywrapfst.o -std=c++11 -Wno-unneeded-internal-declaration -Wno-unused-function
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    pywrapfst.cc:557:40: fatal error: fst/extensions/far/getters.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/home/arif/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-7y6dl6o2/openfst/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-record-3niypfz6/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-7y6dl6o2/openfst/

有人可以帮我解决这个问题吗?

我正在python 3.6 (anaconda)中使用OpenFST-1.5.4Linux Mint 18.3

1 个答案:

答案 0 :(得分:1)

这里有两个问题。


首先,据我所知,尽管有文档记录,pip install方法确实不受支持,甚至无法使用。凯尔·戈曼(Kyle Gorman)(我认为是主要作者之一)对多个论坛话题发表了评论,并做出了如下回复:

  

"Using pip for this doesn't make much sense, and that's out of date anyways."

     

"There's no reason to call pip. The version up there is not compatible with arbitrary OpenFst versions. If you do --enable-python then make and make install, you have already installed pywrapfst for whatever version of OpenFst you're building."


第二,尽管说它可以与“任何Python 2.7或更高版本”一起使用,但实际上仅仅与Python 2.7完全兼容:

  

"Before submitting you may want to test Python 3 with the Python extension. We still develop on Python 2.7, exclusively, unfortunately, and it's not tested on Python 3."

事实上,这就是您尝试使用--enable-python失败的原因:

checking for a version of Python >= '2.1.0'...   File "<string>", line 1
    import sys, string;         ver = string.split(sys.version)[0];     print ver >= '2.1.0'
                                                                        ^
SyntaxError: invalid syntax
no

他们对Python 2.1或更高版本的autoconf测试使用的是在Python 3中非法的语法。它的错误处理效果也不佳,因此,SyntaxError表示您的Python为2.0或更早版本,因此它将中止配置。


如果您进一步查看同一线程,则会发布一个用户NurL:

  

在对配置文件和Makefile进行了大量调整之后,我成功地为Python 3安装了Python扩展。请参见以下Dockerfile:https://gist.github.com/0xnurl/6f97eb39409ea48db31fe315fd1e208f

我显然不能保证这是否有效。

而且,除非您使用与NurL完全相同的目标,否则您必须通读那条巨大的RUN wget命令行,将其分成若干步骤,然后自己做等效的步骤。

您可能会遇到NurL没遇到的问题。 (强烈建议在安装之前或之后至少在结果代码上运行2to3,以确保找不到任何内容。)

但是,由于不支持您尝试做的事情,因此这与您可能会发现的即开即用的东西很接近。如果您无法从那里开始使用它,则可能无法使用该库。