[gdal-dev] [External] : Re: Python binding installation on windows

Fengting Chen fengting.chen at oracle.com
Wed Mar 20 21:32:13 PDT 2024


It turned out that I didn’t specify swig_executable and an old version of swig was used on linux build. After fixing this, the warning was gone.

Back on windows build, with swig 4.2.1, python 3.12.2, setuptools 69.2, cmake still couldn’t install python binding. And I have to manually invoke setup_Release.py. And the installed python binding didn’t work. It has the following error:

Traceback (most recent call last):
  File "C:\gdal_win_build\gdal-3.8.4\pkg\gdal\python\lib\site-packages\osgeo\__init__.py", line 30, in swig_import_helper
    return importlib.import_module(mname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gdal_win_build\SDK\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 921, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 813, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1289, in create_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\gdal_win_build\gdal-3.8.4\pkg\gdal\python\Scripts\gdal_polygonize.py", line 5, in <module>
    from osgeo.gdal import UseExceptions, deprecation_warn
  File "C:\gdal_win_build\gdal-3.8.4\pkg\gdal\python\lib\site-packages\osgeo\__init__.py", line 35, in <module>
    _gdal = swig_import_helper()
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\gdal_win_build\gdal-3.8.4\pkg\gdal\python\lib\site-packages\osgeo\__init__.py", line 32, in swig_import_helper
    return importlib.import_module('_gdal')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gdal_win_build\SDK\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_gdal'

Any idea?

From: Even Rouault <even.rouault at spatialys.com>
Date: Wednesday, March 20, 2024 at 6:46 PM
To: Fengting Chen <fengting.chen at oracle.com>, gdal-dev at lists.osgeo.org <gdal-dev at lists.osgeo.org>
Subject: Re: [External] : Re: [gdal-dev] Python binding installation on windows


Le 20/03/2024 à 23:11, Fengting Chen a écrit :
After upgrading setuptools, the installation on windows worked. Just curious that why “GDAL-3.8.4-py3.6.egg-info” is created under the site-packages on windows, while I set up the PYTHON_ROOT to use python 3.12 and clean up the build directory to rebuild everything.

On the other hand, on linux, when using python 3.12 for the build, the installation gave a lot of warnings like “/scratch/gdal/gdal-3.8.4/dist/lib/python3.12/site-packages/osgeo/ogr.py:5954: SyntaxWarning: invalid escape sequence '\*'” . It seems that this is the new warning from python 3.12. But I don’t see this warning in the windows build, which made me suspect if I was really building on windows using python 3.12.

Which SWIG version do you use? And can you paste line 5954 (and a few ones before and after) of your ogr.py ?

I can't reproduce locally any warning with SWIG 4.1.1 and python 3.12.0 on my Linux. And on our CI with Fedora Rawhide and Python 3.12.2 and SWIG 4.2.1, there is no warning either:

cf https://github.com/OSGeo/gdal/actions/runs/8365025972/job/22901857183<https://urldefense.com/v3/__https:/github.com/OSGeo/gdal/actions/runs/8365025972/job/22901857183__;!!ACWV5N9M2RV99hQ!ORD5c8IPzxNqFDmAs-8SsYYcQxF4HMFO92KcfmAGiHp8EYKXOw6_SJmW-YrJ1HSgUMEz6XDj6TANONhAva5jVB0qAJ07$>



--

http://www.spatialys.com<https://urldefense.com/v3/__http:/www.spatialys.com__;!!ACWV5N9M2RV99hQ!ORD5c8IPzxNqFDmAs-8SsYYcQxF4HMFO92KcfmAGiHp8EYKXOw6_SJmW-YrJ1HSgUMEz6XDj6TANONhAva5jVO0-1Qwb$>

My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240321/636537a2/attachment-0001.htm>


More information about the gdal-dev mailing list