Error importing scipy for SAGE notebook

asked 2017-02-11 16:03:29 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

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]]
mymodel(x) = a*x + b
myfit = find_fit(mydata,mymodel,solution_dict=True)
points(mydata,color='purple') + plot(

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/", 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/
  File "/Applications/", line 697, in find_fit
    from scipy.optimize import leastsq
  File "/Applications/", 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!!!!

edit retag flag offensive close merge delete


This error is really weird. Where and how exactly are you launching the Sage Mac app?

kcrisman gravatar imagekcrisman ( 2017-02-11 17:13:03 -0500 )edit

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.

al gravatar imageal ( 2017-02-12 03:11:29 -0500 )edit

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?

kcrisman gravatar imagekcrisman ( 2017-02-13 08:43:31 -0500 )edit

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)

al gravatar imageal ( 2017-06-24 00:30:14 -0500 )edit

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "", line 10, in <module> exec compile(u'open("","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("aW1wb3J0IHNjaXB5CngsIHkgPSB2YXIoJ3ggeScpClcgPSBwbG90M2Qoc2luKHBpKigoeCleMisoeSleMikpLzIsKHgsLTEsMSksKHksLTEsMSksIGZyYW1lPUZhbHNlLCBjb2xvcj0ncHVycGxlJywgb3BhY2l0eT0wLjgpClMgPSBzcGhlcmUoKDAsMCwwKSxzaXplPTAuMywgY29sb3I9J3JlZCcsIGFzcGVjdF9yYXRpbz1bMSwxLDFdKQpzaG93KFcgKyBTLCBmaWdzaXplPTgp"),globals())+"\n"); execfile(os.path.abspath("")) File "", line 1, in <module>

al gravatar imageal ( 2017-06-24 00:32:42 -0500 )edit