Skip to content

Instantly share code, notes, and snippets.

@0xnurl
Last active October 23, 2021 17:35
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xnurl/0087148273ca60a1d52f67e3f8920f0d to your computer and use it in GitHub Desktop.
Save 0xnurl/0087148273ca60a1d52f67e3f8920f0d to your computer and use it in GitHub Desktop.
Installing OpenFST Native Python Extension on MacOS

Installing OpenFst Native Python Extension on MacOS

Starting from version 1.5, OpenFst has offered a native Python module, making the use of external wrappers like PyFst unnecessary. This has been greatly helpful since PyFst doesn't support Python 3.

1. Install OpenFst

  • Download OpenFst 1.5.4 or above from http://openfst.cs.nyu.edu/twiki/bin/view/FST/FstDownload

  • Unzip, untar: $ tar xzvf openfst-1.5.4.tar.gz

  • $ ./configure --enable-python --enable-far

    • --enable-far will make OpenFst install the library files needed for the Python OpenFst extension.
    • --enable-python will install the pywrapfst Python module, but not neccessarily to the Python version you intend to use. You may need to set the global Python version to 2.7, for example using pyenv.
  • $ ./make

  • $ ./make install

2. Optional: create a Python virtual environment

Say you want to use Python 3.6:

  • $ virtualenv -p $(which python3.6) venv
  • $ source venv/bin/activate

3. Install the OpenFst Python package

  • $ export CFLAGS="-std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7"
    • -std=c++11 makes the compiler use the correct C standard for OpenFst
    • -stdlib=libc++ makes the compiler use the standard C library OpenFst uses
  • $ pip install openfst

4. Using the Python module

See http://www.openfst.org/twiki/bin/view/FST/PythonExtension

@awiso
Copy link

awiso commented Dec 14, 2017

If we run into installation issues with make, can we do to fix?

make[3]: *** [fstarcsort] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment