[Tutor] confusion about scipy

Evert Rol evert.rol at gmail.com
Wed Feb 8 17:10:04 CET 2012

> ImportError                               Traceback (most recent call last)
> C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
> execfile(fname, glob, loc)
>    166             else:
>    167                 filename = fname
> --> 168             exec compile(scripttext, filename, 'exec') in glob, loc
>    169     else:
>    170         def execfile(fname, *where):
> C:\Users\as\hemanta\noorm.py in <module>()
>      1 import numpy as np
> ----> 2 from scipy import brentq
>      3 import matplotlib.pyplot as plt
>      4 from pylab import twinx
>      5 from scipy.integrate import quad
> ImportError: cannot import name brentq
> Question:
> like 'from pylab import twinx' why could not i write 'from scipy
> import brentq'.Instead i have to write 'from scipy.optimize import
> brentq'.But why???

Because that's where the scipy developers put the brentq function: in the optimize module.
It's basically the same as your line 5, where quad is in the integrate module in the scipy package.

It makes sense to organise a large library into (sub)packages/(sub)modules. Just as the tutorial shows as well: http://docs.python.org/tutorial/modules.html#packages
The fact that twinx can be imported straight from the pylab module, is actually just a convenient shortcut.


More information about the Tutor mailing list