[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] fix unable to load *.pyd files with Python 3.8.x on Windows

From: Jun Omae <jun66j5_at_gmail.com>
Date: Sun, 10 May 2020 13:27:46 +0900


I noticed Python bindings is unable to load with Python 3.8.x on Windows, while trying
to run check-swig-py.

C:\usr\src\subversion\trunk-py3> python.exe -c "from svn import core; print(core.SVN_VERSION)"
Traceback (most recent call last):
   File "C:\usr\src\subversion\trunk-py3\Release\python\libsvn\core.py", line 14, in swig_import_helper
     return importlib.import_module(mname)
   File "C:\usr\apps\python38\lib\importlib\__init__.py", line 127, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
   File "<frozen importlib._bootstrap>", line 556, in module_from_spec
   File "<frozen importlib._bootstrap_external>", line 1101, in create_module
   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed while importing _core: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   File "<string>", line 1, in <module>
   File "C:\usr\src\subversion\trunk-py3\Release\python\svn\core.py", line 26, in <module>
     from libsvn.core import *
   File "C:\usr\src\subversion\trunk-py3\Release\python\libsvn\core.py", line 17, in <module>
     _core = swig_import_helper()
   File "C:\usr\src\subversion\trunk-py3\Release\python\libsvn\core.py", line 16, in swig_import_helper
     return importlib.import_module('_core')
   File "C:\usr\apps\python38\lib\importlib\__init__.py", line 127, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_core'

Investigating the issue, I found related changes in What's New In Python 3.8 [1].

According to the document, DLL dependencies for *.pyd file doesn't search the directories
in PATH environment since Python 3.8 on Windows. We should call os.add_dll_directory() to
add search paths to resolve the dependencies.

I created patch to resolve the issue using moduleimport option of %module directive.
After attached patch, *.pyd file is successfully loaded and tests for Python bindings pass.

* subversion/bindings/swig/include/svn_global.swg
   (SVN_PYTHON_MODULEIMPORT): Add custom code to add search paths to resolve DLL
   dependencies when importing libsvn/*.pyd file.

* subversion/bindings/swig/core.i
* subversion/bindings/swig/svn_client.i
* subversion/bindings/swig/svn_delta.i
* subversion/bindings/swig/svn_diff.i
* subversion/bindings/swig/svn_fs.i
* subversion/bindings/swig/svn_ra.i
* subversion/bindings/swig/svn_repos.i
* subversion/bindings/swig/svn_wc.i
   Add moduleimport option with SVN_PYTHON_MODULEIMPORT to %module directive for

[1] https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew

Jun Omae <jun66j5_at_gmail.com> (大前 潤)

Received on 2020-05-10 06:28:03 CEST

This is an archived mail posted to the Subversion Dev mailing list.