Search code examples
python-3.xsaxon

pip install saxonche v 12.1.0 produces FileNotFoundError


On Windows10 in a brand new virtual environment created with Python 3.11.2

python -m venv effnve

I activated the VE and then did

pip install saxonche

as per saxonche's homepage.

Every time I now start python, I get:

Error processing line 1 of C:\ff\effnve\Lib\site-packages\_preload_saxonche_12.1.0.pth:

  Traceback (most recent call last):
    File "<frozen site>", line 186, in addpackage
    File "<string>", line 1, in <module>
    File "<string>", line 18, in <module>
  FileNotFoundError: .load-order-saxonche-12.1.0 not found

Remainder of file ignored

The file .load-order-saxonche-12.1.0 is right there in C:\ff\effnve\Lib\site-packages

I tried tweaking _preload_saxonche_12.1.0.pth, to no avail. For the sake of completeness here it is, with my tweaks designated in the comments.

import sys; exec("
import ctypes
import os
import site

is_pyinstaller = getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS')

for d in site.getsitepackages():
    # the above line will retrieve ['C:\ff\effnve', 'C:\ff\effnve\Lib\site-packages']
    # so it'll always fall down the else-clause, hence 
    # tweak 1: start only if you have a path with site-packages 
    if 'site-packages' in d: 
        load_order_filepath = os.path.join(d, '.load-order-saxonche-12.1.0')
        
        if os.path.isfile(load_order_filepath):
            with open(load_order_filepath) as file:
                load_order = file.read().split()
            for lib in load_order:
                lib_path = os.path.join(d, lib)
                if not is_pyinstaller or os.path.isfile(lib_path):
                    ctypes.WinDLL(lib_path)
                    print(ctypes.WinDLL(lib_path))    # tweak: check it loads all 3 dll's. 
#                break    # tweak: this break was originally 8 eight spaces from start of line. Why?
#                         # Do you only need the first dll? Don't understand.  
        else:   # tweak: this else was originally at the start of the line. Why? 
            if not is_pyinstaller:        
                raise FileNotFoundError('.load-order-saxonche-12.1.0' + ' not found')
                print(d) # tweak to find out what it did not find. 
")

I would post this as a issue on GitHub or the like, but I couldn't find any other place to share this, that's why I'm posting it here.

The reason for using saxonche is that I need a Python library that supports XSLT 2.0.


Solution

  • https://pypi.org/project/saxonche/ has 12.2 now which should solve the problem.