Skip to content

Instantly share code, notes, and snippets.



Created Mar 14, 2018
What would you like to do?
Compile OpenFST Python Extension for Python 3
FROM ubuntu:16.04
# Use bash (Ubuntu default is dash)
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Ubuntu packages
RUN apt-get update && apt-get install -y ssh gcc=4:5.3.1-1ubuntu1 g++=4:5.3.1-1ubuntu1 make vim zlib1g-dev libbz2-dev libssl-dev python-dev man libreadline-dev build-essential libreadline-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev python3 python3-dev
# Install Python 3.6 from source for optimizations
RUN cd /tmp && wget && tar xzvf Python-3.6.0.tgz && cd Python-3.6.0 && ./configure && make && make install && cd /tmp && wget && python3
# Create virtualenv for Python 3.6
RUN pip3 install virtualenv && cd ~ && virtualenv -p $(which python3) venv
# Compile OpenFST with Python extension for Python 3 and Install
RUN wget && tar xzvf openfst-1.6.6.tar.gz && cd openfst-1.6.6/ && pushd ./src/extensions/python/ && mv && vim -c ":1755" -c ':s/"write/b"write' -c ":wq" pywrapfst.pyx && pip3 install cython && cython -f --cplus -3 pywrapfst.pyx -o && popd && ./configure --enable-far --enable-python && vim -c ":%s/PYTHON_CPPFLAGS = -I\/usr\/include\/python2.7/PYTHON_CPPFLAGS = -I\/usr\/local\/include\/python3.6m/" -c ":%s/PYTHON_LDFLAGS = -L\/usr\/lib\/python2.7 -lpython2.7/PYTHON_LDFLAGS = -L\/usr\/local\/lib\/python3.6/" -c ":%s/PYTHON_SITE_PKG = \/usr\/lib\/python2.7/PYTHON_SITE_PKG = \/root\/venv\/lib\/python3.6\/site-packages/" -c ":%s/PYTHON_VERSION = 2.7/PYTHON_VERSION = 3.6/" -c ":%s/lib\/python2.7\/dist-packages/lib\/python3.6\/site-packages/" -c ":wq" ./src/extensions/python/Makefile && make && make install && cp /usr/local/lib/python3.6/site-packages/pywrapfst.* /root/venv/lib/python3.6/site-packages/ && echo 'export LD_LIBRARY_PATH="/usr/local/lib/fst/:/usr/local/lib/:$LD_LIBRARY_PATH"' >> ~/.bashrc
# Result
# A virtual environment with Python 3 will be created in /root/venv and will have the python OpenFST extension properly installed

This comment has been minimized.

Copy link

@shuttle1987 shuttle1987 commented Oct 20, 2018

I'm glad you managed to get this together because I'm currently working on a project that may need to install this ( and we are are using exclusively Python 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.