Project

Profile

Help

Problems to use self built Python extension on Windows: ImportError: DLL load failed while importing saxonche

Added by Martin Honnen almost 2 years ago

I have tried to build the SaxonC 12.0 HE extension on Windows and I think the extension finally has been built fine.

Now on trying to use it, however, it doesn't seem to find a library:

C:\Program Files\Saxonica\SaxonCHE12.0\pypi>dir
..

 Verzeichnis von C:\Program Files\Saxonica\SaxonCHE12.0\pypi

01/26/2023  11:11 AM    <DIR>          .
01/14/2023  07:19 AM    <DIR>          ..
01/26/2023  10:58 AM    <DIR>          build
01/26/2023  11:03 AM            18,432 nodekind.cp39-win_amd64.pyd
01/26/2023  11:11 AM               563 parse_ietf_date_test1.py
01/14/2023  07:19 AM               160 pyproject.toml
01/26/2023  10:50 AM    <DIR>          python_saxon
01/14/2023  07:19 AM             6,787 README.md
01/14/2023  07:19 AM                25 requirements.txt
01/14/2023  07:19 AM    <DIR>          samples
01/26/2023  11:03 AM           517,632 saxonche.cp39-win_amd64.pyd
01/26/2023  11:02 AM             3,082 setup.py
01/14/2023  07:19 AM            58,998 test_saxonc.py
01/14/2023  07:19 AM             4,095 test_saxon_schema.py
01/14/2023  07:19 AM               533 tox.ini
              10 Datei(en),        610,307 Bytes
               5 Verzeichnis(se), 505,411,121,152 Bytes frei

C:\Program Files\Saxonica\SaxonCHE12.0\pypi>py
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from saxonche import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing saxonche: Das angegebene Modul wurde nicht gefunden.

My environment PATH contains C:\Program Files\Saxonica\SaxonCHE12.0\libs\win and the SaxonC command samples and C++ samples run fine and find any dlls.

What else do I have to set to make sure the Python module finds the (I suppose) C/C++ DLLs?


Replies (4)

Please register to reply

RE: Problems to use self built Python extension on Windows: ImportError: DLL load failed while importing saxonche - Added by Martin Honnen almost 2 years ago

I have now tried to built and use the Python extension under WSL Ubuntu but I get a similar error

mh@LibertyDell:~/libsaxon-HEC-linux-v12.0/pypi$ python3
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from saxonche import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /home/mh/libsaxon-HEC-linux-v12.0/pypi/saxonche.cpython-310-x86_64-linux-gnu.so: undefined symbol: j_callTemplateReturningValue

I am kind of lost which setting is missing.

RE: Problems to use self built Python extension on Windows: ImportError: DLL load failed while importing saxonche - Added by O'Neil Delpratt almost 2 years ago

I have also reproduced the same error on linux. Something strange going on here. I will create a bug issue for this problem.

RE: Problems to use self built Python extension on Windows: ImportError: DLL load failed while importing saxonche - Added by Matt Patterson 6 months ago

We currently have improved build scripts that correctly produced wheels which correctly bundle the compiled C extensions and their dependencies. Once 12.5 ships and the HE mirror repository is updated post-release, you should be able to run the following gradle task to build a fully-functioning wheel yourself:

$ ./gradlew hec_python_repair_wheel
C:\> ./gradlew.bat hec_python_repair_wheel

The wheel will be found in the build/hec/python directory.

RE: Problems to use self built Python extension on Windows: ImportError: DLL load failed while importing saxonche - Added by Matt Patterson 6 months ago

Oh, I should note that we now require the use of pyenv, or pyenv-win, to manage which python interpreter is used. If you want to tweak this for a local build you can either just override the pyenv task (I've pasted it in here)

def pyenvTask = tasks.register("pyenv", PythonPyenv) {
  pyenvExe = pyenvExeTask.map { it.pyenv.get() }
  pythonVersion = "3.12.2"
  pythonBuildDefinitionsDir = layout.projectDirectory.dir("python")
}

Or, you could add your own set of tasks to handle this using the task classes we've built. You can see how this works by looking at the tasks that do this in build-doc.gradle.

(The bug created to reference this was #5860)

    (1-4/4)

    Please register to reply