oracle / graalpython

A high-performance embeddable Python 3 runtime for Java
https://www.graalvm.org/python/
Other
1.24k stars 107 forks source link

Meson failure installing numpy with graalpy-maven-plugin #434

Open zenbones opened 1 week ago

zenbones commented 1 week ago

On windows 11, using the graalpy-maven-plugin...

`

org.graalvm.python graalpy-maven-plugin numpy .* ${project.basedir}/python-resources process-graalpy-resources

`

...yields this error from Meson...

`Collecting numpy Downloading numpy-2.0.2.tar.gz (18.9 MB) ---------------------------------------- 18.9/18.9 MB 3.1 MB/s eta 0:00:00 auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\include\numpy\ndarrayobject.h auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\include\numpy\npy_3kcompat.h auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\src\multiarray\compiled_base.c auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\src\multiarray\dlpack.c auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\src\multiarray\dtype_transfer.c auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\src\multiarray\methods.c auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\src\multiarray\stringdtype\dtype.c auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\src\umath\override.c auto-patching C API usages in C:\Users\david\AppData\Local\Temp\pip-install-_qpjhkgz\numpy_cca38dee130b41b0884b1cf835bfb30b\numpy_core\src\umath_rational_tests.c Looking for GraalPy patches for numpy Patching package numpy using C:\Users\david\AppData\Local\org.graalvm.polyglot\python\python-home\7f99e649dc51b21db2b83ce56bc9742eefe66415\lib-graalpython\patches\numpy\numpy-2.0.0.patch WARNING: GraalPy needs the 'patch' utility to apply compatibility patches. Please install it using your system's package manager. Installing build dependencies: started Installing build dependencies: still running... Installing build dependencies: still running... Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Installing backend dependencies: started Installing backend dependencies: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): still running... Preparing metadata (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error

? Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 2 ?─> [56 lines of output]

? Encountered error while generating package metadata. ?─> See above for output.`

msimacek commented 1 week ago

Hi, @zenbones, you need to install the patch utility so that pip can apply patches to add compatibility fixes. It says that in the output:

WARNING: GraalPy needs the 'patch' utility to apply compatibility patches. Please install it using your system's package manager.

Sorry that it's not more visible, in the next release it should be printed in color. Maybe we should make it hard error instead.

zenbones commented 3 days ago

Thanks. A few comments.

1) It's a warning, which generally means the process can work around his on its own, so yes, an error might be better. 2) The warning (or error) assumes I know what the 'patch' utility is, or how to install it properly. Maybe adding the shell (or other) installation instructions would help others in the same situation. This is not a utility I've ever had to deal with before in either Python or Java.

So... what's the patch utility (which I'm about to ask my web search client)?

zenbones commented 3 days ago

Having looked up the patch utility, the AI generated 'answer' is 'apt install patch' or 'brew install patch'... oh, hey, I'm on a windows system. Trying to find the equivalent, but, you know, any help appreciated.

msimacek commented 3 days ago

True, on Linux it's something that you typically already have and on Mac it's easy to install. This patching logic was added way before we had any windows support and we didn't properly re-evaluate it for windows. The patch tool should be available as a part of [Git for Windows], but we need to look at how to make it available so that the maven plugin would pick it up. We're also working on building the numpy wheel for windows, so you wouldn't have to do any of this.

timfel commented 3 days ago

FYI, I used the one from gnuwin32 on my machine

timfel commented 3 days ago

Note that this is the setup I have:

  1. Install (at least) Visual Studio 2022 Build Tools (e.g. winget install Microsoft.VisualStudio.2022.BuildTools on a recent Win11)
  2. Get patch.exe and put it somewhere you'll find it again, in a path without spaces
  3. Start a "Developer PowerShell for VS 2022"
  4. Put patch.exe on the PATH (e.g. $Env:PATH+=";c:\my\full\path\to\the\folder\that\containes\patchexe\")
  5. Now use this prompt to make your graalpy venv and install packages

You can also fork the graalpy repository and run the github action to build windows wheels, download the resulting zip file, and pip install the numpy.whl file from that zip file. (see https://github.com/oracle/graalpython/blob/master/.github/workflows/build-windows-amd64-wheels.yml#L14)