Bug 158447 - Use PyConfig for setting Python home directory
Summary: Use PyConfig for setting Python home directory
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.6.3.1 rc
Hardware: All All
: medium normal
Assignee: Buovjaga
URL:
Whiteboard: target:24.8.0
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-29 21:47 UTC by Gwyn Ciesla
Modified: 2024-05-09 07:45 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Patch to use PyConfig (1.94 KB, patch)
2023-12-20 17:11 UTC, Buovjaga
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gwyn Ciesla 2023-11-29 21:47:43 UTC
Description:
libreoffice fails to build with Python 3.13.0a1.

/builddir/build/BUILD/libreoffice-7.6.3.1/pyuno/source/loader/pyuno_loader.cxx: In function ‘void pyuno_loader::setPythonHome(const rtl::OUString&)’:
/builddir/build/BUILD/libreoffice-7.6.3.1/pyuno/source/loader/pyuno_loader.cxx:133:5: error: ‘Py_SetPythonHome’ was not declared in this scope; did you mean ‘Py_GetPythonHome’?
  133 |     Py_SetPythonHome(wide); // deprecated since python 3.11
      |     ^~~~~~~~~~~~~~~~
      |     Py_GetPythonHome

According to https://docs.python.org/3.13/whatsnew/3.13.html:
Remove the following old functions to configure the Python initialization, deprecated in Python 3.11:
    PySys_AddWarnOptionUnicode(): use PyConfig.warnoptions instead.
    PySys_AddWarnOption(): use PyConfig.warnoptions instead.
    PySys_AddXOption(): use PyConfig.xoptions instead.
    PySys_HasWarnOptions(): use PyConfig.xoptions instead.
    PySys_SetArgvEx(): set PyConfig.argv instead.
    PySys_SetArgv(): set PyConfig.argv instead.
    PySys_SetPath(): set PyConfig.module_search_paths instead.
    Py_SetPath(): set PyConfig.module_search_paths instead.
    Py_SetProgramName(): set PyConfig.program_name instead.
    Py_SetPythonHome(): set PyConfig.home instead.
    Py_SetStandardStreamEncoding(): set PyConfig.stdio_encoding instead, and set also maybe PyConfig.legacy_windows_stdio (on Windows).
    _Py_SetProgramFullPath(): set PyConfig.executable instead.


https://docs.python.org/3.13/whatsnew/3.13.html

https://bugzilla.redhat.com/show_bug.cgi?id=2250857

Actual Results:
libreoffice fails to build with Python 3.13.0a1.

/builddir/build/BUILD/libreoffice-7.6.3.1/pyuno/source/loader/pyuno_loader.cxx: In function ‘void pyuno_loader::setPythonHome(const rtl::OUString&)’:
/builddir/build/BUILD/libreoffice-7.6.3.1/pyuno/source/loader/pyuno_loader.cxx:133:5: error: ‘Py_SetPythonHome’ was not declared in this scope; did you mean ‘Py_GetPythonHome’?
  133 |     Py_SetPythonHome(wide); // deprecated since python 3.11
      |     ^~~~~~~~~~~~~~~~
      |     Py_GetPythonHome

Expected Results:
Build succeeds


Reproducible: Always


User Profile Reset: No

Additional Info:
Python 3.13 will likely be shipped in Fedora 41.
Comment 1 Roman Kuznetsov 2023-12-01 18:33:51 UTC
Cloph, Stephan, should we do something with this?
Comment 2 Gwyn Ciesla 2023-12-01 18:35:32 UTC
For added context, Python 3.13 will be the system Python in Fedora 41, which should be released in late 2024.
Comment 3 Buovjaga 2023-12-20 17:11:15 UTC
Created attachment 191534 [details]
Patch to use PyConfig

I created a patch for this and at least it doesn't break anything (tested with a Python extension and running a UI test), but the problem is that our Alma Linux machines in our CI say in their console log:

checking for python3 version... 3.6

Python Initialization Configuration is said to be "New in version 3.8": https://docs.python.org/3/c-api/init_config.html

So I can't submit the patch right away. Probably someone can look at this next year.
Comment 4 Buovjaga 2023-12-21 10:03:10 UTC
Submitted https://gerrit.libreoffice.org/c/core/+/161089 Thanks to Thorsten and Noel for fallback tip.
Comment 5 Commit Notification 2024-05-09 07:33:28 UTC
Ilmari Lauhakangas committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/da0e9240bf6505ac3a67ff985705950566c66144

tdf#158447 Use PyConfig for setting Python home directory with Python >= 3.8

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.