[petsc-dev] Problem pip installing petsc4py on existing PETSc installation

Samar Khatiwala samar.khatiwala at earth.ox.ac.uk
Fri Aug 29 07:24:01 CDT 2025


Hi Satish,

Thanks for taking the time to help debug this. That you ran into the same issue is reassuring in a way (that I wasn’t doing something silly). Sounds like there’s not much to be done about it but hopefully this only affects a few older versions of petsc4py.

It is bizarre that pip is not accepting that 3.0.12 satisfies the requirement. I thought I found a clever way to override what is in pyproject.toml by specifying “cython==3.0.12” in a constraints.txt file with the -c option. But pip ignored that too and proceeded to download cython 3.1.3.

As for re-downloading packages (cython, numpy) even when they’re already installed is I think by pip’s design because these are build-time requirements (and not runtime requirements).

Thanks,

Samar

> On Aug 29, 2025, at 1:51 AM, Satish Balay <balay.anl at fastmail.org> wrote:
> 
> On Thu, 28 Aug 2025, Satish Balay wrote:
> 
>> 
>> Likely:
>> 
>> pip install -v cython=3.0.12 petsc4py==3.21.1
> 
> https://urldefense.us/v3/__https://petsc.org/release/petsc4py/install.html__;!!G_uCfscf7eWS!ccM-EknCNavnpHXV7-_uoEddj8ar6876_brlmFbYTOL8M-IaAH5Y_NIbolpNF7JlYXLunOXzURWtoLI0czE1HjrvaZuc3x0XTwfBaw$ 
> 
> suggests:
> 
> $ python -m pip install src/binding/petsc4py
> 
> However:
>>>>> 
> balay at pj02:~/petsc$ which cython
> ~/.local/bin/cython
> balay at pj02:~/petsc$ cython --version
> Cython version 3.0.12
> balay at pj02:~/petsc$ 
> balay at pj02:~/petsc$ PETSC_DIR=/home/balay/petsc PETSC_ARCH=arch-linux-c-debug python -m pip install --verbose src/binding/petsc4py
> Using pip 23.3.2 from /usr/lib/python3.12/site-packages/pip (python 3.12)
> Defaulting to user installation because normal site-packages is not writeable
> Processing ./src/binding/petsc4py
>  Running command pip subprocess to install build dependencies
>  Collecting cython>=3
>    Downloading cython-3.1.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.metadata (4.7 kB)
>  Collecting numpy
>    Downloading numpy-2.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (62 kB)
>       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.1/62.1 kB 2.1 MB/s eta 0:00:00
>  Collecting setuptools
>    Downloading setuptools-80.9.0-py3-none-any.whl.metadata (6.6 kB)
>  Downloading cython-3.1.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (3.3 MB)
>     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 8.3 MB/s eta 0:00:00
>  Downloading numpy-2.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (16.6 MB)
>     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.6/16.6 MB 8.0 MB/s eta 0:00:00
>  Downloading setuptools-80.9.0-py3-none-any.whl (1.2 MB)
>     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 8.9 MB/s eta 0:00:00
>  Installing collected packages: setuptools, numpy, cython
>  Successfully installed cython-3.1.3 numpy-2.3.2 setuptools-80.9.0
> ....
> <<<<
> 
> I'm not sure why `3.0.12` is not satisfying the `cython>=3` requirement - and `cython-3.1.3` is installed for this requirement
> 
> Ok - try to force 3.0.12:
>>>> 
> balay at pj02:~/petsc$ git diff
> diff --git a/src/binding/petsc4py/pyproject.toml b/src/binding/petsc4py/pyproject.toml
> index 6987c0389ed..35b08945f2a 100644
> --- a/src/binding/petsc4py/pyproject.toml
> +++ b/src/binding/petsc4py/pyproject.toml
> @@ -1,6 +1,6 @@
> [build-system]
> requires = [
> -  "cython >= 3",
> +  "cython == 3.0.12",
>   "numpy",
>   "setuptools",
> ]
> balay at pj02:~/petsc$ PETSC_DIR=/home/balay/petsc PETSC_ARCH=arch-linux-c-debug python -m pip install --verbose src/binding/petsc4py
> Using pip 23.3.2 from /usr/lib/python3.12/site-packages/pip (python 3.12)
> Defaulting to user installation because normal site-packages is not writeable
> Processing ./src/binding/petsc4py
>  Running command pip subprocess to install build dependencies
>  Collecting cython==3.0.12
>    Downloading Cython-3.0.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.3 kB)
>  Collecting numpy
>    Downloading numpy-2.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (62 kB)
>       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.1/62.1 kB 1.9 MB/s eta 0:00:00
>  Collecting setuptools
>    Downloading setuptools-80.9.0-py3-none-any.whl.metadata (6.6 kB)
>  Downloading Cython-3.0.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB)
>     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.5/3.5 MB 41.4 MB/s eta 0:00:00
>  Downloading numpy-2.3.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (16.6 MB)
>     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.6/16.6 MB 4.9 MB/s eta 0:00:00
>  Downloading setuptools-80.9.0-py3-none-any.whl (1.2 MB)
>     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 5.2 MB/s eta 0:00:00
>  Installing collected packages: setuptools, numpy, cython
>  Successfully installed cython-3.0.12 numpy-2.3.2 setuptools-80.9.0
> ...
> ...
>  Building wheel for petsc4py (pyproject.toml) ... done
>  Created wheel for petsc4py: filename=petsc4py-3.21.6-cp312-cp312-linux_x86_64.whl size=11282654 sha256=462b32dc3706d841a0fca5c7e9ba7b6127b0633cd943eef3784dc8f956375c1b
>  Stored in directory: /tmp/pip-ephem-wheel-cache-du9_e3hc/wheels/ab/ca/ed/9a2ee0271ce3654f467915ae1f28d46ace120416127b0c8cf1
> Successfully built petsc4py
> Installing collected packages: petsc4py
> Successfully installed petsc4py-3.21.6
> balay at pj02:~/petsc$ pip list --user
> Package  Version
> -------- -------
> Cython   3.0.12
> petsc4py 3.21.6
> balay at pj02:~/petsc$ git branch
> * release-3.21
> balay at pj02:~/petsc$ 
>>>>> 
> 
> Ok - now 3.0.12 is getting used (the local install is skipped again - and a new pkg is downloaded/installed as part of the build?) , and the build is now successful
> 
> Satish



More information about the petsc-dev mailing list