[Python] PyNEC fails to import (PyInit__PyNEC error) on WSL Ubuntu with Python 3.12/3.11/3.9

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to use PyNEC (Python bindings for NEC2++) on a fresh Windows 11 WSL2 Ubuntu 24.04 setup. My goal is to call NEC directly from Python, instead of shelling out to the nec2++ CLI and parsing CSV output.

    What I’ve done & what's happened so far:

    • For each of Python 3.12, 3.11, and 3.9 in succession I created clean virtual environments each time and installed with:

    pip install --upgrade pip setuptools wheel
    pip install "numpy<2" cython
    pip install PyNEC


    • Verified install completes (Successfully installed PyNEC-1.7.3.6).


    • In site-packages, I only see _PyNEC.cpython-...so, no PyNEC/ directory.


    • import _PyNEC or from _PyNEC import NEC fails with:`

    ImportError: dynamic module does not define module export function (PyInit__PyNEC)

    • Probing with importlib.util.find_spec shows _PyNEC is present but PyNEC is not.

    What I’ve researched


    • PyPI wheels show PyNEC worked for Python 3.9 but failed for 3.11.


    • Examples online (e.g. afiskon/pynec-examples) use import PyNEC, but my install never provides that module.


    • I’ve also tried installing the NEC2++ repo directly (necpp), but it evidently doesn’t include Python bindings anymore.

    Questions


    • Is PyNEC currently incompatible with Python ≥ 3.9, or is there a build flag / step I’m missing?


    • Has anyone recently gotten PyNEC to work under WSL Ubuntu?


    • Is there a known workaround (shim module, alternate binding, or pinned Python version)?

    At the moment my only workaround is to run the nec2++ CLI and parse CSV in Python, which works but isn’t ideal.

    Continue reading...

Compartilhe esta Página