lmfit 'Parameters' object has no attribute '_asteval'

25 views
Skip to first unread message

Pablo Crespo Peremarch

unread,
Dec 25, 2019, 4:15:26 AM12/25/19
to lmfit-py

Hi all!


I had worked with a previous version of lmfit so far. However, I updated lmfit package to version 0.9.15 in Python 2.7 64b, and the following error is raising when adding initial parameters or creating a new Parameters object (i.e. p = lmfit.Parameters()):


Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27_64b\lib\site-packages\lmfit\parameter.py", line 65, in __init__
    super(Parameters, self).__init__(self)
  File "C:\Python27_64b\lib\collections.py", line 48, in __init__
    self.update(*args, **kwds)
  File "C:\Python27_64b\lib\site-packages\lmfit\parameter.py", line 87, in update
    for sym in other._asteval.user_defined_symbols():
AttributeError: 'Parameters' object has no attribute '_asteval'

I was just trying to do this simple example from https://lmfit.github.io/lmfit-py/examples/example_emcee_Model_interface.html:


import numpy as np
import lmfit

def double_exp(x, a1, t1, a2, t2): return a1*np.exp(-x/t1) + a2*np.exp(-(x-0.1) / t2) model = lmfit.Model(double_exp) truths = (3.0, 2.0, -5.0, 10.0) x = np.linspace(1, 10, 250) np.random.seed(0) y = double_exp(x, *truths)+0.1*np.random.randn(x.size) p = model.make_params(a1=4, t1=3, a2=4, t2=3)

but it crashes with the error I showed above. The same error is raised when jus trying to create a new Parameters object:


import lmfit

p = lmfit.Parameters()

 

I am using the following versions:

  • Python 2.7 64b
  • lmfit 0.9.15
  • numpy 1.16.5
  • uncertainties 3.1.2
  • six 1.11.0
  • asteval 0.9.16

I would appreciate if you could help me out.


Thank you!


Pablo.

Matt Newville

unread,
Dec 26, 2019, 11:37:26 AM12/26/19
to lmfit-py
Hi Pablo,

On Wed, Dec 25, 2019 at 1:15 AM Pablo Crespo Peremarch <crespope...@gmail.com> wrote:

Hi all!


I had worked with a previous version of lmfit so far. However, I updated lmfit package to version 0.9.15 in Python 2.7 64b, and the following error is raising when adding initial parameters or creating a new Parameters object (i.e. p = lmfit.Parameters()):


Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27_64b\lib\site-packages\lmfit\parameter.py", line 65, in __init__
    super(Parameters, self).__init__(self)
  File "C:\Python27_64b\lib\collections.py", line 48, in __init__
    self.update(*args, **kwds)
  File "C:\Python27_64b\lib\site-packages\lmfit\parameter.py", line 87, in update
    for sym in other._asteval.user_defined_symbols():
AttributeError: 'Parameters' object has no attribute '_asteval'

I was just trying to do this simple example from https://lmfit.github.io/lmfit-py/examples/example_emcee_Model_interface.html:


import numpy as np
import lmfit

def double_exp(x, a1, t1, a2, t2): return a1*np.exp(-x/t1) + a2*np.exp(-(x-0.1) / t2) model = lmfit.Model(double_exp) truths = (3.0, 2.0, -5.0, 10.0) x = np.linspace(1, 10, 250) np.random.seed(0) y = double_exp(x, *truths)+0.1*np.random.randn(x.size) p = model.make_params(a1=4, t1=3, a2=4, t2=3)

but it crashes with the error I showed above. The same error is raised when jus trying to create a new Parameters object:



Sorry for the trouble.  I'm not sure what the problem is.  That is, I don't quite understand how `lmfit.Parameters()` or `model.make_params()` would get to `Parameters.update()` where that exception comes from, or how a `Parameters` instance would have `_asteval` of None after initialization and inside of `Parameters.update()`. 

For a test of a fresh Python 2.7 environment, I just did

~> conda create -n py27a python=2.7 numpy scipy matplotlib h5py
~> conda activate py27a
~> pip install lmfit  

This gives me versions of  python: 2.7.17,  lmfit: 0.9.15, scipy: 1.2.1, numpy: 1.16.5, asteval: 0.9.17, uncertainties: 3.1.2
and the example works for me.   

So, I think it *should* work and my guess would be that something is wrong with your installation.  I would suggest finding and explicitly deleting any and all folders named

   C:\Python27_64b\lib\site-packages\lmfit*
   C:\Python27_64b\lib\site-packages\asteval*

and re-doing `pip install lmfit`.  

Hope that helps, 

--Matt 

Pablo Crespo Peremarch

unread,
Jan 2, 2020, 4:33:27 AM1/2/20
to lmfit-py
Thank you Matt!

The problem was the version of Python 2.7. I updated to Python 2.7.17, and it works!

Pablo.
Reply all
Reply to author
Forward
0 new messages