Sequitur G2P Installation Guide for Windows
Edited by Liang-Yu (Davidson) Chen, 2012/10/31
back to homepage
Note
- The following installation guide is based on this discussion and walkthrough. This intends to install Sequitur G2P on Windows.
- The black text is copied from the original text; the red text is my comment or amendment.
- The tools I used include: (yours might be different from mine; make necessary changes accordingly)
- My installation environment:
- Windows7 64-bit SP1 Tradiational Chinese
- ASUS A52J Laptop with Intel Core i5 CPU M430 @ 2.27GHz and 8GB of RAM
General notes from the author of the guide
- All needed environment variables should be carefully set
- Python distutils needs minor modification since MinGW tools report loose versions, but distutils requires strict versions
- Some g2p Python source files need minor modifications since Windows Python does not have resource module, pickle under Windows needs explicit "wb" or "rb" specification
- Some g2p C++ source modification is required to link against libiberty.a MinGW static library and some UNIX signals are absent on Windows
- Python library with mingw-compatible symbols needs to be created to link Python module
- Compiled G2P works fine under Windows, it took a little more than 1 day to train model-5 for cmuict.
Installation walkthrough
- I assume that Python 2.7 is in PYTHONDIR. If you have other version, change commands accordingly.
- Install MinGW; add path to {MinGWDir}\bin\ (e.g. C:\MinGW\bin\) to your environment variable.
- Install SWIG
- Download swigwin http://www.swig.org/download.html
- Unzip anywhere, add folder containing swig.exe to PATH
- Set environment variables
- PYTHON_INCLUDE = PYTHONDIR\include
- PYTHON_LIB = PYTHONDIR\libs\python25.lib
- Download and Install numpy binaries for your version of Python
- Compile g2p using mingw
- patch sequitur.i line 147 or else there will be warning (add //)
- patch file misc.py before build. If you don't do this, g2p.py will not work. Since Windows Python does not have resource module, memory usage will not be reported.
- remove "resource" from import statement:
import gc, os, sys, types
- comment out memory usage reporting:
# pageSize = resource.getpagesize()
- patch file SequiturTool.py before build
- Line 160: replace
model = pickle.load(open(self.options.modelFile))
with
model = pickle.load(open(self.options.modelFile,"rb"))
- Line 186: replace
f = open(self.options.newModelFile, 'w')
with
f = open(self.options.newModelFile, 'wb')
- patch PYTHONDIR\lib\distutils\cygwinccompiler.py, (since ld.exe returns its version as 2.20.51.20100123, but StrictVersion requires 2.20.51 format)
- add (near "from distutils.version import StrictVersion"):
from distutils.version import LooseVersion
- replace StrictVersion calls (ld_exe and dllwrap_exe) with LooseVersion
- Well... I didn't get this part at all, so I went on looking for other ways to bypass this one. Another suggestion is to delete all occurrence of the string "-mno-cygwin" in this file. This works for me, but it was suggested that this might create other problems so better keep an original copy of this file before you do any changes.
- copy cdefs.h from cygwin's cygwin-1.7.9-1.tar.bz2 into mingw's include\sys dir (any cygwin mirror e.g. http://mirrors.xmission.com/cygwin/release/cygwin/cygwin-1.7.9-1.tar.bz2 )
- I can't find this bz2 file anywhere on the Internet. What I did here is to simply find a sample of this cdefs.h file such as this one and manually create the file.
- create file fix.h, it tells compiler that strsignal implemented elsewhere (in mingw it is implemented in libiberty.a). It doesn't say where this file must be stored... I guess it should be stored under g2p directory so Assertions.cc can find it (see next point)
#include <_mingw.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const char * strsignal (int signo);
#ifdef __cplusplus
}
#endif
- patch Assertions.cc since Windows does not support full range of UNIX signals
- add header with strsignal declaration:
#include "fix.h"
- comment out:
// signal(SIGBUS, handler);
// signal(SIGSYS, handler);
- patch Utility.cc
- add header:
#include <cstdio>
- create Python lib with mingw-compatible symbols. If you don't do this, there wil be a lot of undefinded reference errors from linker. Steps are:
- Find python27.dll (it will probably be in %windir%\system32). Mine was found at C:\Windows\SysWOW64
- List the exports from this DLL. I can't find my pexports.exe in MinGW so I had to downloaded it separated from here and extract pexports.exe to my MinGW bin directory. The other thing is that, I couldn't get it to work when I ran this command under c:\mingw\bin\; it works under the SysWOW64 directory
pexports.exe python27.dll > python27.def
- Create libpython27.a (same as above, I got it to work when I ran this command under the SysWOW64 directory)
dlltool --dllname python27.dll --def python27.def --output-lib libpython27.a
- Place libpython25.a in the libs directory of your Python distribution
- Tell python's distutils to link g2p against libiberty.a. If you don't do this, there wil be undefinded reference to 'strsignal' error from linker
- add to end of setup.cfg:
libraries=iberty
- Build
- Command: python setup.py build -c mingw32 > build.log 2>&1
- If you've done everything correctly, there will be something like this in build.log: (some of the lines starting with "copying" might be skipped if you are not running it for the first time)
running build
running build_py
creating build
creating build\lib.win32-2.5
copying Evaluation.py -> build\lib.win32-2.5
copying Minimization.py -> build\lib.win32-2.5
copying SequenceModel.py -> build\lib.win32-2.5
copying SequiturTool.py -> build\lib.win32-2.5
copying g2p.py -> build\lib.win32-2.5
copying misc.py -> build\lib.win32-2.5
copying sequitur.py -> build\lib.win32-2.5
copying sequitur_.py -> build\lib.win32-2.5
copying symbols.py -> build\lib.win32-2.5
copying tool.py -> build\lib.win32-2.5
running build_ext
building '_sequitur_' extension
swigging sequitur.i to sequitur_wrap.cpp
c:\programs\swig\swig.exe -python -c++ -shadow -o sequitur_wrap.cpp sequitur.i
creating build\temp.win32-2.5
creating build\temp.win32-2.5\Release
[gcc compilation]
...... lots of warnings ..............
[g++ linking]
running build_scripts
creating build\scripts-2.5
copying and adjusting g2p.py -> build\scripts-2.5
- and voila, built _sequitur_.pyd will be in build\lib.win32-2.5
- Install
- run:
python setup.py install --skip-build
- Set environment variable PYTHONPATH=PYTHONDIR before using and enjoy!
back to homepage
last updated: 2012/10/31