[petsc-dev] Problem pip installing petsc4py on existing PETSc installation
Satish Balay
balay.anl at fastmail.org
Thu Aug 28 09:07:03 CDT 2025
On Thu, 28 Aug 2025, Samar Khatiwala via petsc-dev wrote:
> Hello,
>
> I’m trying to install petsc4py with pip on a machine with an existing PETSc (3.21.1) (installed without pets4py). When I do:
>
> pip install -v petsc4py==3.21.1
>
> the installation fails. (If I don’t specify the version pip just downloads the latest version and the installation fails in a different way, but that’s not surprising.)
>
> I’ve attached the build log.
>
> If I don’t specify PETSC_DIR etc and just do pip install petsc4py then that works. But I would like to use the existing installed PETSc (yes, I know it is quite old but please bear with me!).
>>>
Successfully installed cython-3.1.3 numpy-2.0.2 setuptools-80.9.0
<snip>
using Cython 3.1.3
cythonizing 'petsc4py/PETSc.pyx' -> 'petsc4py/PETSc.c'
warning: petsc4py/PETSc/petscis.pxi:196:4: '__getsegcount__' relates to the old Python 2 buffer protocol and is no longer used.
warning: petsc4py/PETSc/petscis.pxi:201:4: '__getreadbuffer__' relates to the old Python 2 buffer protocol and is no longer used.
warning: petsc4py/PETSc/petscvec.pxi:585:4: '__getsegcount__' relates to the old Python 2 buffer protocol and is no longer used.
warning: petsc4py/PETSc/petscvec.pxi:590:4: '__getreadbuffer__' relates to the old Python 2 buffer protocol and is no longer used.
warning: petsc4py/PETSc/petscvec.pxi:595:4: '__getwritebuffer__' relates to the old Python 2 buffer protocol and is no longer used.
Error compiling Cython file:
------------------------------------------------------------
...
@classmethod
def Print(
cls,
*args: Any,
sep: str = ' ',
^
------------------------------------------------------------
petsc4py/PETSc/Sys.pyx:159:19: Compiler crash in ExpressionWriter
Compiler crash traceback from this point on:
File "Cython/Compiler/Visitor.py", line 174, in Cython.Compiler.Visitor.TreeVisitor._visit
File "/private/var/folders/d3/w861tc0j755f19272xfkq56w0000gn/T/pip-install-1e_zq9u1/petsc4py_c977438422fb480b9f145e0099e7cf3e/conf/cyautodoc.py", line 28, in visit_UnicodeNode
self.emit_string(node, '')
AttributeError: 'ExpressionWriter' object has no attribute 'emit_string'
error: Cython failure: 'petsc4py/PETSc.pyx' -> 'petsc4py/PETSc.c'
<<<
Perhaps you can try installing/using an older cython version - say 3.0.12 - and see if that works.
Satish
More information about the petsc-dev
mailing list