AttributeError: 'ast' has no attribute 'Num' in MFiX 25.3 with Python 3.14+

Hello,

I encountered a crash when saving projects in MFiX 25.3 running on Python 3.13/3.14. The error is:
AttributeError: module 'ast' has no attribute 'Num'

This is because ast.Num and ast.Str have been removed in recent Python versions. I managed to fix this by making the SimpleEval class backwards compatible in the following file:
mfixgui/tools/simpleeval.py

The fix:
I replaced the static dictionary definitions for ast.Num and ast.Str with a conditional check using hasattr. Around line 291 in mfixgui/tools/simpleeval.py, I changed the code to:

python

        self.nodes = {
            ast.Expr: self._eval_expr,
            ast.Assign: self._eval_assign,
            ast.AugAssign: self._eval_aug_assign,
            ast.Import: self._eval_import,
            # Use conditional unpacking for removed AST attributes
            **({ast.Num: self._eval_num} if hasattr(ast, 'Num') else {}),
            **({ast.Str: self._eval_str} if hasattr(ast, 'Str') else {}),
            ast.Name: self._eval_name,
            # ... rest of the dict
        }

Since the file already handles ast.Constant further down (around line 320), this change allows the GUI to save projects without crashing on newer Python environments while remaining compatible with older versions.

I also noticed ast.Index and ast.Slice are still present in the dictionary. While they didn’t cause a crash in my specific case, they have also been deprecated/removed in newer Python versions and might need similar hasattr checks for full compatibility.

Best regards.

1 Like

Thank you for this!

We just released MFiX version 26.1 and if I had gotten this message sooner I would have included this fix. However, we haven’t seen the issue with our conda-based installation. You wrote Python 3.13/3.14 which is a bit ambiguous. You must be using Python 3.14. (I edited the post topic to reflect this). Our Conda-based installation uses Python 3.13, and this doesn’t seem to be an issue with 3.13, although there is a DeprecationWarning:

ryzen-mfix-26.1:( python
Python 3.13.12 | packaged by conda-forge | (main, Feb  5 2026, 05:53:46) [GCC 14.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.Num
<python-input-1>:1: DeprecationWarning: ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead
<class 'ast.Num'>

But I’m not sure how you got that version? How did you install MFiX 25.3 with Python 3.14? Our standard install is pinned to 3.13 which is why we hadn’t seen this error.

This will definitely become a problem when we move to Python 3.14 so thank you for the report. Instead of all the “hasattr” checks I think it’s OK to just drop the support for ancient Python versions (2.x, 3.6 etc). The file header says “2019” and there’s a more up-to-date version at GitHub - danthedeckie/simpleeval: Simple Safe Sandboxed Extensible Expression Evaluator for Python · GitHub We should update the version we bundle with MFiX, or (probably better) stop carrying around our own version and just get it from conda-forge or PyPi like other dependencies.

– Charles