3

I opened up a Jupyter notebook on which I was working just a couple of weeks ago and went to re-import the modules I had been using (by running the cell again, with no changes), and encountered an unexpected difficulty when trying to import scipy.optimize (even though the exact same command worked just fine before): It tells me that there is no module named 'scipy.optimize._root', and when I look it up, it looks like there is an underscore where there should not be; however, I do not know how to amend this, has this happened to anyone else by chance?

I was trying to import the curve_fit module so that I can do a particular fit to the data that my group and I took in our optics lab class and then print the parameters of the fit.

Initially, I was trying to import curve_fit using

from scipy.optimize import curve_fit

(This had worked in the recent past, but suddenly is resulting in an error.) Next, I tried to just import scipy.optimize, which also gave me the same error.

I expected to be able to import the module, however I am met with the following error message:

ModuleNotFoundError: No module named 'scipy.optimize._root'

  • Are you using virtualenv or something? Make sure you have ```scipy``` installed in your local or global environment, whichever you use, by using ```pip freeze | grep scipy``` – Nikolay Shindarov Nov 05 '19 at 23:17
  • @NikolayShindarov I'm using a Jupyter notebook; the tricky thing is that I've used this exact same cell to import and use curve_fit, and even though I didn't change anything (all I did was re-run the cell), I'm seeing this error. I did also try importing scipy first (which worked smoothly), but when I then tried importing scipy.optimize again, it gave the same error. (Thank you so much for helping, by the way!) – Madie Durand Nov 05 '19 at 23:26

1 Answers1

0

I use import spicy.optimize as op, and then use the op.leastsq(). It worked!

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 06 '22 at 06:09