Installation with Poetry fails on Python 3.12 - error: ‘PyArray_Descr’ {aka ‘struct _PyArray_Descr’} has no member named ‘subarray’
#3541
Description
Problem description
Installation of Gensim version 4.3.2 or current develop branch fails on Python 3.12 when using Poetry - when using pip there is no problem.
Noted this first from a failed run of our CI/CD pipeline, which installs v4.3.2. Two weeks ago it ran successfully.
Steps to reproduce
Success with pip
Run
docker run python:3.12 pip install gensim # for v4.3.2
or
docker run python:3.12 pip install git+https://github.com/piskvorky/gensim.git@develop
The dependencies for the develop branch by pip are:
gensim 4.3.2.dev0
numpy 1.26.4
scipy 1.14.0
smart-open 7.0.4
wrapt 1.16.0
Fail with Poetry
Using this Dockerfile
FROM python:3.12
RUN pip install --upgrade pip poetry --no-cache-dir
COPY pyproject.toml pyproject.toml
RUN poetry install
and this pyproject.toml
[tool.poetry]
name = "gensim-testing"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.12"
# gensim = "4.3.2"
gensim = { git = "https://github.com/piskvorky/gensim.git", branch = "develop" }
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
to build and install current develop branch (or v4.3.2) with the command
docker build -t gensim-build:3.12 .
the result is a failure at the following build step:
running build_ext
building 'gensim.models.word2vec_inner' extension
creating build/temp.linux-x86_64-cpython-312
creating build/temp.linux-x86_64-cpython-312/gensim
creating build/temp.linux-x86_64-cpython-312/gensim/models
gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -I/tmp/tmp2ohmylfq/.venv/include -I/usr/local/include/python3.12 -I/tmp/tmp2ohmylfq/.venv/lib/python3.12/site-packages/numpy/_core/include -c gensim/models/word2vec_inner.c -o build/temp.linux-x86_64-cpython-312/gensim/models/word2vec_inner.o
In file included from /tmp/tmp2ohmylfq/.venv/lib/python3.12/site-packages/numpy/_core/include/numpy/ndarraytypes.h:1909,
from /tmp/tmp2ohmylfq/.venv/lib/python3.12/site-packages/numpy/_core/include/numpy/ndarrayobject.h:12,
from /tmp/tmp2ohmylfq/.venv/lib/python3.12/site-packages/numpy/_core/include/numpy/arrayobject.h:5,
from gensim/models/word2vec_inner.c:771:
/tmp/tmp2ohmylfq/.venv/lib/python3.12/site-packages/numpy/_core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
17 | #warning "Using deprecated NumPy API, disable it with " \
| ^~~~~~~
In file included from /usr/local/include/python3.12/Python.h:38,
from gensim/models/word2vec_inner.c:25:
gensim/models/word2vec_inner.c: In function ‘__pyx_f_5numpy_PyDataType_SHAPE’:
gensim/models/word2vec_inner.c:9365:39: error: ‘PyArray_Descr’ {aka ‘struct _PyArray_Descr’} has no member named ‘subarray’
9365 | __Pyx_INCREF(((PyObject*)__pyx_v_d->subarray->shape));
| ^~
/usr/local/include/python3.12/pyport.h:24:38: note: in definition of macro ‘_Py_CAST’
24 | #define _Py_CAST(type, expr) ((type)(expr))
| ^~~~
/usr/local/include/python3.12/object.h:661:35: note: in expansion of macro ‘_PyObject_CAST’
661 | # define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
| ^~~~~~~~~~~~~~
gensim/models/word2vec_inner.c:1435:27: note: in expansion of macro ‘Py_INCREF’
1435 | #define __Pyx_INCREF(r) Py_INCREF(r)
| ^~~~~~~~~
gensim/models/word2vec_inner.c:9365:5: note: in expansion of macro ‘__Pyx_INCREF’
9365 | __Pyx_INCREF(((PyObject*)__pyx_v_d->subarray->shape));
| ^~~~~~~~~~~~
gensim/models/word2vec_inner.c:9366:36: error: ‘PyArray_Descr’ {aka ‘struct _PyArray_Descr’} has no member named ‘subarray’
9366 | __pyx_r = ((PyObject*)__pyx_v_d->subarray->shape);
| ^~
error: command '/usr/bin/gcc' failed with exit code 1
(I thought this was something to do with the Numpy 2.0 release, but the current develop branch has already pinned Numpy to <2.0. So it seems something else than Numpy is causing this.)
The dependencies by Poetry resolution are the same as by pip.
When using Python 3.11 the installation is successful with Poetry, and the dependencies are the same.
Versions
Python 3.12.4
Poetry 1.8.3