Open edX Calc
raw JSON → 5.0.0 verified Mon Apr 27 auth: no python
A helper library for mathematical calculations and symbolic mathematics, used by Open edX. Current version 5.0.0, requires Python >=3.12. Release cadence is irregular, tied to Open edX releases.
pip install openedx-calc Common errors
error ModuleNotFoundError: No module named 'openedx_calc' ↓
cause Package installed with hyphens but imported with underscores; wrong import path.
fix
Install with 'pip install openedx-calc' then import as 'from openedx_calc import ...'
error AttributeError: 'int' object has no attribute 'replace' ↓
cause Passed an integer instead of a string to calculator().
fix
Ensure the expression is a string: calculator('2+2') not calculator(4).
error ImportError: cannot import name 'evaluate' from 'openedx_calc' ↓
cause 'evaluate' was removed in version 5.0.0; use 'evaluator'.
fix
Replace 'from openedx_calc import evaluate' with 'from openedx_calc import evaluator'.
Warnings
breaking Python 3.12+ only; drop of Python 3.8-3.11 support in version 5.0.0. ↓
fix Upgrade Python to 3.12 or later.
deprecated The 'evaluate' function was renamed to 'evaluator' in version 4.0.0. ↓
fix Use 'from openedx_calc import evaluator' instead of 'from openedx_calc import evaluate'.
gotcha The calculator function expects a string, not a numeric type. Passing a number will cause an AttributeError. ↓
fix Always pass an expression as a string: calculator('2+2').
Imports
- calculator wrong
from calc import calculatorcorrectfrom openedx_calc import calculator - evaluator wrong
from openedx_calc.evaluator import Evaluatorcorrectfrom openedx_calc import evaluator
Quickstart
from openedx_calc import calculator
expr = "2 + 2"
result = calculator(expr)
print(result) # 4