Slepc and complex numbers

I am using the binary package for ubuntu 24.04. If I set petsc for complex numbers slepc4py will not import. Can someone suggest a way round this?

andy@tavy:~/test$ cat test_slepc.py 
from slepc4py import SLEPc
andy@tavy:~/test$ export PETSC_DIR=/usr/lib/petscdir/petsc3.19/x86_64-linux-gnu-real
andy@tavy:~/test$ python test_slepc.py 
andy@tavy:~/test$ export PETSC_DIR=/usr/lib/petscdir/petsc3.19/x86_64-linux-gnu-complex
andy@tavy:~/test$ python test_slepc.py 
Traceback (most recent call last):
  File "/home/andy/test/test_slepc.py", line 1, in <module>
    from slepc4py import SLEPc
  File "/usr/lib/slepc/lib/python3/dist-packages/slepc4py/SLEPc.py", line 7, in <module>
    SLEPc._initialize()
  File "slepc4py/SLEPc/SLEPc.pyx", line 265, in slepc4py.SLEPc._initialize
  File "slepc4py/SLEPc/SLEPc.pyx", line 237, in slepc4py.SLEPc.register
  File "petsc4py/PETSc/Object.pyx", line 280, in petsc4py.PETSc.PyPetscType_Register
ValueError: key: 1211220, cannot register: <class 'slepc4py.SLEPc.ST'>, already registered: <class 'petsc4py.PETSc.Viewer'>
andy@tavy:~/test$

Apologies. I seem to be making a habit of this. I need to set an environment variable for slepc as well. Apologies again.

For those finding this topic later, the env variables needed (to use Ubuntu/Debian complex number packages) are PETSC_DIR and SLEPC_DIR
e.g.

PETSC_DIR=/usr/lib/petscdir/petsc-complex
SLEPC_DIR=/usr/lib/slepcdir/slepc-complex
1 Like