I am converting a Numpy C extension Python project from distutils to meson. I've been following along the meson-python instructions (https://meson-python.readthedocs.io/en/latest/tutorials/introduction.html

I've installed meson / ninja (and everything else...) into a virtualenv (python -m venv venv). Running Python 3.11

Unfortunately the following command fails:

incdir_numpy = run_command(py,
  ['-c', 'import numpy; print(numpy.get_include())'],
  capture: true,
  check: false,
).stdout().strip()

Capturing stderr, gives the error:

>       ModuleNotFoundError: No module named 'numpy' does not exist.

But If I hardcode incdir_numpy to my actual location, it works fine

incdir_numpy = 'venv/lib/python3.11/site-packages/numpy/core/include'

I've tried deactivating / activating the venv and rebuilding, no such luck.

I feel like I'm missing something obvious about meson / numpy and virtual environments?

My changes are here

https://github.com/softwaredoug/np-sims/compare/meson?expand=1#diff-30d8f6be6320feeacf686be94f48c70869b52630e01ea625f0f15adc0d57c3e4R5