Search code examples
pythonsaxonsaxon-c

Making saxon-c available in Python


I have just read that Saxon is now available for Python, and that's just great fun and good, but can anyone write a tutorial on how to make it available for Python/Anaconda/WingIDE or similar? I am used to installing with pip or conda, and pointing to a package/wheel for integration in my environment, but I have never started from scratch, as it feels I am doing here, or am I missing something?

The doc states that:

The Python extension on the Linux and MacOS platforms can be built using the following command:python3 saxon-setup.py build_ext -if

Well, I'm on a windows machine so what then? I've tried to read up on this subject, but recepies and ".h" files seems to be way over my head.

I just really want to get this to work on Python, but for now, I'm stuck with xslt and xpath 1.0 in Python, and having to wrestle through Java for xslt 2+.

Any help would be apreciated!

I will write another question here on StackOverflow, but with focus on how to build using Cython when I have a 64-bit version of Anaconda installed. This seems to be my initial problem.


Solution

  • I have managed to build saxonc for Python on a couple of Windows 10 machines where I had already installed Visual Studio 2017 or 2019 with Python 3 support and C/C++ support.

    The steps are roughly, for the current version of SaxonC HE:

    • Install SaxonC HE 11.3 from Saxonica
    • For Python: update pip
    • Use pip to install Cython: pip install Cython
    • open Powershell for e.g. Python 3.9 (with administrator rights if you installed in C:\Program Files)
    • cd Saxon install dir (e.g. cd C:\Program Files\Saxonica\SaxonC HE 11.3)
    • cd Saxon.C.API\python-saxon
    • run py saxon-setup.py build_ext -if
    • for arbitrary Powershell Windows need to set SAXONC_HOME to the installation dir e.g. $env:SAXONC_HOME='C:\Program Files\Saxonica\SaxonC HE 11.3' and PYTHONPATH: $Env:PYTHONPATH += ";C:\Program Files\Saxonica\SaxonC HE 11.3\Saxon.C.API\python-saxon" to ensure that "import saxonc" in any Python program finds the saxonc module

    For Saxon-C HE 1.2.1 they are:

    • Install Saxon-C HE 1.2.1 from Saxonica
    • For Python: update pip
    • Use pip to install Cython: pip install Cython
    • open Powershell for Python 3.7 (with administrator rights if you installed in C:\Program Files)
    • cd Saxon install dir (e.g. cd C:\Program Files\Saxonica\SaxonHEC1.2.1)
    • cd Saxon.C.API\python-saxon
    • run py saxon-setup.py build_ext -if
    • for arbitrary Powershell Windows need to set: $Env:PYTHONPATH += ";C:\Program Files\Saxonica\SaxonHEC1.2.1\Saxon.C.API\python-saxon" to ensure that "import saxonc" in any Python program finds the saxonc module