PyFST Setup Mac

From 11-711
Jump to: navigation, search
# Install Homebrew. There’s a good chance you’ve already done this.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor

# Install pip. If you can’t sudo, then pip is almost certainly installed, so skip this step.
sudo easy_install pip

# Install wget
brew install wget

# Install graphviz, which draws FSTs
brew install graphviz

# Create a prefix directory if one does not exist yet
cd ~
mkdir -p prefix
cd prefix
export PREFIX=$PWD
echo $PREFIX

# Download OpenFST
mkdir -p openfst
cd openfst
wget http://www.openfst.org/twiki/pub/FST/FstDownload/openfst-1.4.1.tar.gz
tar xzf openfst-1.4.1.tar.gz

# Build OpenFST
rm -rf objdir
mkdir objdir
cd objdir
../openfst-1.4.1/configure --prefix=$PREFIX --enable-pdt --enable-bin --enable-ngram-fsts
make -j 4
make install

# Setting up your environment. Note that the double quotes are important.
echo "export PREFIX=$(cd; pwd)/prefix" >> ~/.bashrc

# Export other environment variables. Note that the single quotes are important.
# Also note that the DYLD_LIBRARY_PATH line is only necessary on Mac.
echo 'export CPLUS_INCLUDE_PATH=$PREFIX/include:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=$PREFIX/lib:$LIBRARY_PATH
export LIBRARY_PATH=$PREFIX/lib/fst:$LIBRARY_PATH
export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$PREFIX/lib/fst:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$PREFIX/lib/fst:$PREFIX/lib:$DYLD_LIBRARY_PATH
export PATH=$PREFIX/bin:$PATH
export PYTHONPATH=$PREFIX/lib/python2.7/site-packages:$PYTHONPATH' >> ~/.bashrc

# By default on Mac ~/.bash_profile is executed, but ~/.bashrc is not
# so we'll make ~/.bash_profile call ~/.bashrc, so they're both called at startup.
echo "source ~/.bashrc" >> ~/.bash_profile

# At this point you should close your current terminal and open a new one
echo $PREFIX
# should print /Users/<your username>/prefix

# Bug fix: According to the mac compiler, isspace is ambiguously defined. Disambiguate it by explicitly using std::is space.
for f in `find $PREFIX/include/fst -type f | xargs grep isspace | cut -f 1 -d ':' | uniq`; do
  sed -i .bak 's/isspace/std::isspace/g' $f
done

cd $PREFIX
wget http://demo.clab.cs.cmu.edu/cdyer/pyfst-0.2.5.tar.gz
tar xzf pyfst-0.2.5.tar.gz
cd pyfst-0.2.5/
python setup.py install --prefix=$PREFIX

#if you have sudo:
sudo pip install ipython[all]

# If you don't have sudo:
cd $PREFIX
virtualenv ./env
. env/bin/activate
pip install ipython[all]

# Now you should be able to run the command
ipython notebook
# and create a new workbook. In the first cell, type
import fst
# and press shift-enter. There should be no error.
# In the next cell type
a = fst.Acceptor()
a
# and press shift-enter. It should draw an FSA with one state.
# If so, then you're good to go!