JohannesBuchner / PyMultiNest

Pythonic Bayesian inference and visualization for the MultiNest Nested Sampling Algorithm and PyCuba's cubature algorithms.
http://johannesbuchner.github.io/PyMultiNest/
Other
194 stars 88 forks source link

Moving from getargspec to getfullargspec made PyMultiNest not Python2 compatible anymore? #226

Closed thjsal closed 1 year ago

thjsal commented 1 year ago

In #225 e543962de8b67d7d821e01657686e41ceb2b508c deprecated syntax was corrected to run PyMultiNest with Python 3.11. However, that seems to have made PyMultiNest not compatible with Python2 anymore. At least I cannot run the demo example with Python 2.7.18 anymore, but it gives a lot of errors like this: TypeError: SafeLoglikelihood() takes exactly 4 arguments (3 given), which are caused by the fact that AttributeError: 'module' object has no attribute 'getfullargspec' and nargsremains thus 3 instead of 4. I would suggest either mentioning in the readme file that python 2.7 is not supported anymore (assuming that is the issue?), or do the following (works for me at least):

    try:
        if sys.version_info[0] == 3:
            nargs = len(inspect.getfullargspec(LogLikelihood).args) - inspect.ismethod(LogLikelihood)
        else:
            nargs = len(inspect.getargspec(LogLikelihood).args) - inspect.ismethod(LogLikelihood)
    except:
        pass
JohannesBuchner commented 1 year ago

The second solution sounds good to me. Could you please put in a pull request?

thjsal commented 1 year ago

Thanks! The issue was solved in #227 .