-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Summary
The atomizer crashes immediately on Python 3.12+ because analyzeSBML.py imports the imp module, which was removed from the Python standard library in Python 3.12 (PEP 594, Python 3.12 changelog).
Environment
- Python: 3.12.12 (also affects 3.13+)
- PyBioNetGen: 0.7.9 (installed via
uv pip install bionetgen) - setuptools: 69.5.1 (needed for
pkg_resources, which is also used bybionetgen/main.py) - python-libsbml: 5.21.0
- OS: macOS Sonoma (arm64)
Steps to Reproduce
pip install bionetgen
bionetgen atomize -i model.xml -o output/Error
Traceback (most recent call last):
File ".../bin/bionetgen", line 10, in <module>
sys.exit(main())
File ".../bionetgen/main.py", line 631, in main
app.run()
File ".../cement/core/foundation.py", line 956, in run
return_val = self.controller._dispatch()
File ".../cement/ext/ext_argparse.py", line 835, in _dispatch
return func()
File ".../bionetgen/main.py", line 555, in atomize
runAtomizeTool(self.app)
File ".../bionetgen/core/main.py", line 95, in runAtomizeTool
from bionetgen.atomizer import AtomizeTool
File ".../bionetgen/atomizer/__init__.py", line 1, in <module>
from .atomizeTool import AtomizeTool
File ".../bionetgen/atomizer/atomizeTool.py", line 1, in <module>
import bionetgen.atomizer.libsbml2bngl as ls2b
File ".../bionetgen/atomizer/libsbml2bngl.py", line 15, in <module>
import bionetgen.atomizer.atomizer.moleculeCreation as mc
File ".../bionetgen/atomizer/atomizer/moleculeCreation.py", line 15, in <module>
from . import analyzeSBML
File ".../bionetgen/atomizer/atomizer/analyzeSBML.py", line 9, in <module>
import imp
ModuleNotFoundError: No module named 'imp'
Root Cause
In atomizer/atomizer/analyzeSBML.py, line 9:
import impThe imp module was deprecated in Python 3.4 and fully removed in Python 3.12 per PEP 594. The only usage appears to be imp.reload(), which should be replaced with importlib.reload().
Secondary Issue
There is also a related (but separate) issue: bionetgen/main.py line 21 uses:
from pkg_resources import packagingThe pkg_resources module requires setuptools to be installed, which is no longer bundled by default in Python 3.12+ virtual environments created by uv or with python -m venv. This is a separate bug from the imp issue but compounds the problem — even after manually installing setuptools<70 to get past pkg_resources, the atomizer still fails on the imp import.
Suggested Fix
In atomizer/atomizer/analyzeSBML.py, replace:
import impwith:
import importlibAnd replace any usage of imp.reload(module) with:
importlib.reload(module)For the pkg_resources issue in bionetgen/main.py, consider replacing:
from pkg_resources import packagingwith:
from importlib.metadata import versionor using packaging directly (pip install packaging).
Impact
This blocks all SBML → BNGL conversion on Python 3.12+, which is the current stable Python release series. Users must downgrade to Python 3.11 to use the atomizer, which is increasingly impractical as the ecosystem moves forward.