cellmodeller / CellModeller

GPU-accelerated multicellular modelling framework
http://cellmodeller.github.io/CellModeller/
Other
57 stars 48 forks source link

replace use of deprecated imp for importlib.utils #50

Closed alonfnt closed 7 months ago

alonfnt commented 7 months ago

The imp library was deprecated in Python 3.4 and has been finally removed of the standard library in version 3.12. Instead, importlib needs to be used -- otherwise people with the new version of Python won't be able to run the code.

I have also removed the imp library from ModuleRegulator as it was not being used anyway.

avimanyu786 commented 7 months ago

Hi @alonfnt, Thanks so much for your pull request! I tried to test your branch with Python 3.12 but faced the following error when I tried to load a pickle file:

Traceback (most recent call last):
  File "/workspace/CellModeller/CellModeller/GUI/PyGLCMViewer.py", line 194, in loadPickle
    sim = Simulator(self.modName, \
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/CellModeller/CellModeller/Simulator.py", line 80, in __init__
    self.module = importlib.util.import_from_spec(module_spec)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'importlib.util' has no attribute 'import_from_spec'
Aborted (core dumped)

When I looked into the change I found that we should be using module_from_spec instead of import_from_spec in this line . When I made the new change, I was able to load the pickle file successfully and resume the simulation.

Please make this change in your branch so we can merge it soon. Thanks again.

alonfnt commented 7 months ago

Hey @avimanyu786, you are completely right! My memory failed me there... Sorry for not checking properly! It should be fixed now :)