Sunday, August 07, 2016

Compiling aspell-python

While the Unofficial Windows Binaries for Python has aspell-python for Python 3.4, it does not have one for Python 3.5. Thus, we've got to compile it ourselves.

Since Python 3.5 requires Visual Studio 2015, we first have to modify C:\tools\python\tools\Lib\distutils\cygwinccompiler.py to recognize Visual Studio 2015
--- cygwinccompiler.py
+++ cygwinccompiler.py
@@ -82,7 +82,18 @@ def get_msvcr():
         elif msc_ver == '1600':
             # VS2010 / MSVC 10.0
             return ['msvcr100']
+        elif msc_ver == '1700':
+            # Visual Studio 2012 / Visual C++ 11.0
+            return ['msvcr110']
+        elif msc_ver == '1800':
+            # Visual Studio 2013 / Visual C++ 12.0
+            return ['msvcr120']
+        elif msc_ver == '1900':
+            # Visual Studio 2015 / Visual C++ 14.0
+            # "msvcr140.dll no longer exists" http://blogs.msdn.com/b/vcblog/archive/2014/06/03/visual-studio-14-ctp.aspx
+            return ['vcruntime140']
         else:
+            # to do: can we make this futureproof?
             raise ValueError("Unknown MS Compiler version %s " % msc_ver)
 



Next, download and unzip aspell-python from https://github.com/WojciechMula/aspell-python

 In setup.3.py, modify get_include_dirs() from
        return [] 
to
        return ['c:/tools/Aspell/include'] 
this is for aspell-python build scripts to find the aspell.h

In  aspell.c, modify static PyTypeObject aspell_AspellType from
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
to
    PyVarObject_HEAD_INIT(NULL, 0)

and insert after
     speller_as_sequence.sq_contains = m_contains;
the following
    Py_TYPE(&aspell_AspellType) = &PyType_Type;
as per instructions on https://docs.python.org/3.5/c-api/typeobj.html#c.PyObject.ob_type

Copy C:\tools\Aspell\lib\libaspell.dll.a to the directory with aspell-python source code, and rename it to aspell.lib.

Then build it normally using
python setup.3.py build
python setup.3.py install

No comments: