[Python] Problems running subprocesses from Spyder IDE

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have an executable that I need to run in a Python script, with an input configuration written in an ASCII file. Both files are in the same directory as the script.

    The barebones script that will exhibit the issue described below is something like:

    import subprocess

    result = subprocess.run(["model.exe", "input.txt"],
    capture_output=True, text=True)


    If I run the script in a command prompt it executes without issue. The same goes if I start python in cmd and run the command on its own.

    UPDATE: The .exe also runs fine through VS Code.

    UPDATE 2: The .exe does not run in Jupyter either.

    However, if I run the script directly in Spyder I get the following:

    print(result.stderr)

    Traceback (most recent call last):
    File "model.py", line 1, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "py_wake\__init__.py", line 12, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "py_wake\deficit_models\__init__.py", line 1, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "py_wake\deficit_models\selfsimilarity.py", line 3, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "py_wake\deficit_models\no_wake.py", line 3, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "py_wake\deficit_models\deficit_model.py", line 5, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "py_wake\utils\model_utils.py", line 6, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "py_wake\site\__init__.py", line 1, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "py_wake\site\_site.py", line 1, in <module>
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
    File "matplotlib\__init__.py", line 1270, in <module>
    File "matplotlib\__init__.py", line 738, in __setitem__
    ValueError: Key backend: 'module://matplotlib_inline.backend_inline' is not a valid value for backend; supported values are ['gtk3agg', 'gtk3cairo', 'gtk4agg', 'gtk4cairo', 'macosx', 'nbagg', 'notebook', 'qtagg', 'qtcairo', 'qt5agg', 'qt5cairo', 'tkagg', 'tkcairo', 'webagg', 'wx', 'wxagg', 'wxcairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
    [PYI-30188:ERROR] Failed to execute script 'model' due to unhandled exception!


    It seems that the model.exe contains a model.py Python file that runs into some internal issue, but essentially the entire error stack seems to be related to the frontend/ visual things, via matplotlib and bootstrap.

    I am using Python 3.11, within Spyder 5.4.3 (Qt 5.15.2, PyQt5 5.15.9, Windows 10), but the issue also appears in Spyder 6.0.1 (Qt 5.15.2, PyQt5 5.15.11). I have tried many things, including running in and out of virtual environments, restarting the kernel, and restarting Spyder.

    The answers to several question I found online don't seem applicable, because here the author seems to have issues with the subprocess module; I have tested this outside Spyder and it works fine; the issue from here does not seem to relate to Spyder and here the issue is seemingly in reverse to the one I have.

    Any help would be much appreciated!

    Continue reading...

Compartilhe esta Página