0

我试图根据指南安装 OpenFST Python 扩展。这样做有两种选择。
第一个选项是--enable-python在配置 OpenFst 期间发布,我尝试过但失败了。
所以我选择了第二个选项。我使用以下命令成功安装了 OpenFST:

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

然后我尝试openfst使用pip:安装 PyPi 包
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.

4

1 回答 1

1

这里有两个问题。


首先,据我所知,尽管已记录在案,但该pip install方法确实不受支持,甚至无法正常工作。Kyle Gorman(我认为他是主要作者之一)评论了多个论坛主题,回复如下:

“使用pip它没有多大意义,而且无论如何都已经过时了。”

“没有理由调用 pip。那里的版本与任意 OpenFst 版本不兼容。如果你执行 --enable-python 然后 make 和 make install,你已经为你正在构建的任何版本的 OpenFst 安装了 pywrapfst。”


其次,尽管说它适用于“任何 Python 2.7 或更高版本”,但它实际上只适用于 Python 2.7:

“在提交之前,您可能希望使用 Python 扩展测试 Python 3。不幸的是,我们仍然在 Python 2.7 上进行开发,但它没有在 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在安装之前或之后运行生成的代码,以确保它没有找到任何东西。)

但这与您可能会得到开箱即用的东西一样接近,因为您尝试做的事情不受支持。如果你不能从那里为自己工作,你可能就不能使用这个库。

于 2018-06-25T18:31:02.687 回答