[Python] rpy2 on Windows prints “Error importing in API mode … only ABI” — how to force ABI...

Discussão em 'Python' iniciado por Stack, Agosto 12, 2025.

  1. Stack

    Stack Membro Participativo

    I’m developing a Flask app on Windows that calls R via rpy2. On every run or during pytest collection I see this message:

    Error importing in API mode: ImportError('On Windows, cffi mode "ANY" is only "ABI".')
    Trying to import in ABI mode.


    I understand this isn’t a crash; rpy2 falls back to ABI and works. I’d like to reliably force ABI mode (which is recommended on Windows) and suppress this message in both my app and tests.

    Environment Details OS: Windows 10 (build 26100) Python: 3.12.10 (venv) R: 4.5.1 rpy2: [please fill your exact version] Flask + pytest python-dotenv for reading .env

    What I expect

    • rpy2 to use ABI mode on Windows without printing the API/ABI message
    • A consistent way to apply this across app

    What I’ve tried

    • .env approach (preferred)

    RPY2_CFFI_MODE=ABI

    • Code-level env

    import os os.environ["RPY2_CFFI_MODE"] = "ABI" # then import rpy2

    But still the error is there, also cleared cache...

    Continue reading...

Compartilhe esta Página