Error importing scipy for SAGE notebook
The following code -which I got as an example off the web- works fine in a SageCell but doesn't run in my Sage notebook. Here is the code. Help or hints please!!!
mydata = [[1,3],[2,7],[3,13],[4,24]]
var('a,b')
mymodel(x) = a*x + b
myfit = find_fit(mydata,mymodel,solution_dict=True)
points(mydata,color='purple') + plot(
mymodel(
a=myfit[a],
b=myfit[b]
),
(x,0,4,),
color='red'
)
Here is the error message:
Traceback (most recent call last): a=myfit[a],
File "", line 1, in <module>
File "/private/var/folders/18/gmqqrhkd1wb4l1pv6sldfr5r0000gp/T/tmpSL56oE/___code___.py", line 6, in <module>
myfit = find_fit(mydata,mymodel,solution_dict=True)
File "sage/misc/lazy_import.pyx", line 386, in sage.misc.lazy_import.LazyImport.__call__ (/Applications/SageMath-7.2.app/Contents/Resources/sage/src/build/cythonized/sage/misc/lazy_import.c:3627)
File "/Applications/SageMath-7.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 697, in find_fit
from scipy.optimize import leastsq
File "/Applications/SageMath-7.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/scipy/__init__.py", line 103, in <module>
raise ImportError(msg)
ImportError: Error importing scipy: you cannot import scipy while
being in scipy source directory; please exit the scipy source
tree first, and relaunch your python intepreter.
Thanks very much!!!!
This error is really weird. Where and how exactly are you launching the Sage Mac app?
Thanks for asking.
I have SAGE 7.2 installed on my mac with OSX 10.10.5. It opens in the Firefox browser and runs fine- I have quite a few worksheets- but this is the fist time I tried to use the command find_fit which is part of scipy. It seems scipy is included in the SAGE I installed, yet i get this error.
I checked, and the code runs fine in the SAGE cell and no doubt (haven't tried it ) in the Cloud. I would rather have it running in the notebook so I can easily save a pdf of the output and save the code.
Huh, that will take a little time to look into, then, because it seems to be very specific to your setup. What happens if you just do "import scipy" or "import numpy" in a new worksheet? The same thing?
Hi kcrisman- I finally got back to this issue and am trying to resolve it. The problem is that for some reason I can't get 3d graphics to work in my sage notebook. I thought scipy would be part of the sagemath package 7.2, so am surprised it may need to be installed. In any case, just saw your suggestion of trying to do "import scipy" so I added it to a program found on the web, which runs fine in sage cell. Here is the result.
import scipy x, y = var('x y') W = plot3d(sin(pi*((x)^2+(y)^2))/2,(x,-1,1),(y,-1,1), frame=False, color='purple', opacity=0.8) S = sphere((0,0,0),size=0.3, color='red', aspect_ratio=[1,1,1]) show(W + S, figsize=8)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_17 ...(more)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_17.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("aW1wb3J0IHNjaXB5CngsIHkgPSB2YXIoJ3ggeScpClcgPSBwbG90M2Qoc2luKHBpKigoeCleMisoeSleMikpLzIsKHgsLTEsMSksKHksLTEsMSksIGZyYW1lPUZhbHNlLCBjb2xvcj0ncHVycGxlJywgb3BhY2l0eT0wLjgpClMgPSBzcGhlcmUoKDAsMCwwKSxzaXplPTAuMywgY29sb3I9J3JlZCcsIGFzcGVjdF9yYXRpbz1bMSwxLDFdKQpzaG93KFcgKyBTLCBmaWdzaXplPTgp"),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>