Error on missing Python module in Meson setup

Started by Daniel Gustafssonalmost 4 years ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t46922
psql -h localhost -U postgres

Built from patchset v3 (message #3), July 28, 2026 at 01:43 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t46922_3 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t46922_3 && git checkout t46922_3

Patchset v3 (message #3) is on t46922_3

Jump to latest
#1Daniel Gustafsson
daniel@yesql.se

When setting up a postgres tree with Meson on an almost empty Debian 11 VM I
hit an error on "meson setup -Ddebug=true build ." like this:

Program python3 found: YES (/usr/bin/python3)
meson.build:987:2: ERROR: Unknown method "dependency" in object.

The error in itself isn't terribly self-explanatory. According to the log the
error was a missing Python package:

Traceback (most recent call last):
File "<string>", line 20, in <module>
File "<string>", line 8, in links_against_libpython
ModuleNotFoundError: No module named ‘distutils.core'

Installing the distutils package fixes it, but it seems harsh to fail setup on
a missing package. Would something like the attached make sense?

--
Daniel Gustafsson https://vmware.com/

Attachments:

meson_python.diffapplication/octet-stream; name=meson_python.diff; x-unix-mode=0644Download+6-2
#2Andres Freund
andres@anarazel.de
In reply to: Daniel Gustafsson (#1)
Re: Error on missing Python module in Meson setup

Hi,

On 2022-11-14 14:23:02 +0100, Daniel Gustafsson wrote:

When setting up a postgres tree with Meson on an almost empty Debian 11 VM I
hit an error on "meson setup -Ddebug=true build ." like this:

Program python3 found: YES (/usr/bin/python3)
meson.build:987:2: ERROR: Unknown method "dependency" in object.

The error in itself isn't terribly self-explanatory. According to the log the
error was a missing Python package:

Traceback (most recent call last):
File "<string>", line 20, in <module>
File "<string>", line 8, in links_against_libpython
ModuleNotFoundError: No module named ‘distutils.core'

Installing the distutils package fixes it, but it seems harsh to fail setup on
a missing package. Would something like the attached make sense?

The error is a bit better in newer versions of meson:
meson.build:986: WARNING: <PythonExternalProgram 'python3' -> ['/usr/bin/python3']> is not a valid python or it is missing distutils
but we do still error out weirdly afterwards.

We probably should report this to the meson folks regardless of us working
around it or not.

diff --git a/meson.build b/meson.build
index 058382046e..1a7e301fc9 100644
--- a/meson.build
+++ b/meson.build
@@ -984,8 +984,12 @@ pyopt = get_option('plpython')
if not pyopt.disabled()
pm = import('python')
python3_inst = pm.find_installation(required: pyopt.enabled())
-  python3_dep = python3_inst.dependency(embed: true, required: pyopt.enabled())
-  if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt.enabled())
+  if python3_inst.found()
+    python3_dep = python3_inst.dependency(embed: true, required: pyopt.enabled())
+    if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt.enabled())
+      python3_dep = not_found_dep
+    endif
+  else
python3_dep = not_found_dep
endif
else

Perhaps worth simplifying a bit. What do you think about:

pyopt = get_option('plpython')
python3_dep = not_found_dep
if not pyopt.disabled()
pm = import('python')
python3_inst = pm.find_installation(required: pyopt.enabled())
if python3_inst.found()
python3_dep_int = python3_inst.dependency(embed: true, required: pyopt.enabled())
if cc.check_header('Python.h', dependencies: python3_dep_int, required: pyopt.enabled())
python3_dep = python3_dep
endif
endif
endif

Greetings,

Andres Freund

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Andres Freund (#2)
Re: Error on missing Python module in Meson setup

On 15 Nov 2022, at 01:25, Andres Freund <andres@anarazel.de> wrote:
On 2022-11-14 14:23:02 +0100, Daniel Gustafsson wrote

Installing the distutils package fixes it, but it seems harsh to fail setup on
a missing package. Would something like the attached make sense?

The error is a bit better in newer versions of meson:
meson.build:986: WARNING: <PythonExternalProgram 'python3' -> ['/usr/bin/python3']> is not a valid python or it is missing distutils
but we do still error out weirdly afterwards.

We probably should report this to the meson folks regardless of us working
around it or not.

Thats better, but I wish meson could be more specific since it at that point
should know if Python works at all or is missing distutils.

Perhaps worth simplifying a bit. What do you think about:

...

Agreed, that's a better version. The attached version with a disabler object
is even more to the point, and seems to works on my box both with and without
distutils and libpython. Is this the correct way to use disablers?

--
Daniel Gustafsson https://vmware.com/

Attachments:

t46922_3
meson_python-v2.diffapplication/octet-stream; name=meson_python-v2.diff; x-unix-mode=0644Download+5-5