title: import libraries into python scrapy shell.
body: <p>I launch the shell by : </p>
  
  <pre><code>scrapy shell 'some_url'
  </code></pre>
  
  <p>I want to use numpy in the shell: </p>
  
  <pre><code>import numpy
  a = numpy.random.random(2)
  a = array([ 0.64836678,  0.72713776])
  </code></pre>
  
  <p>These all worked fine. The problem comes when I try use numpy in a function definition: </p>
  
  <pre><code>In [23]: def foo(n): return numpy.random.random(n) 
  In [24]: foo(2) 
  In [24]: foo(2)
  ---------------------------------------------------------------------------
  NameError                                 Traceback (most recent call last)
  &lt;ipython-input-24-3ab2f4e33a15&gt; in &lt;module&gt;()
  ----&gt; 1 foo(2)
  
  &lt;ipython-input-23-8383e2a3c452&gt; in foo(n)
  ----&gt; 1 def foo(n) : return numpy.random.random(n)
  
  NameError: global name 'numpy' is not defined
  </code></pre>
  
  <p>My current solution is:</p>
  
  <pre><code>def foo(n) :import numpy ; return numpy.random.random(n)
  </code></pre>
  
  <p>Can someone help explain this problem and propose more elegant solution? </p>
  
  <p>thanks in advance.</p>