title: Calling Python function that requires libraries from another file
body: <p>I have a script called "custom_functions.py" with functions I've written to simplify my work. Each custom function calls different libraries. "custom_functions.py" looks something like this:</p>
  
  <pre><code># This is custom_functions.py
  import pandas as pd
  import numpy as np
  
  def create_df():
     return pd.DataFrame({'a': [1, 2, 3]})
  
  def create_array():
     return np.array([1, 2, 3])
  </code></pre>
  
  <p>Over the last few months, as I've added functions to custom_functions.py, there are more and more libraries I need to import for me to be able to call the script into another file (let's call it "main.py"). It seems inefficient/unnecessary to load in the libraries for all the functions when I end up only needing one.</p>
  
  <p>Is there a way to call only e.g. <code>create_array</code> without needing to also load in the libraries required for <code>create_df</code>? It'd be ideal, for example, if I could remove all library calls in custom_functions.py and only import the necessary libraries in main.py before I call in a specific function from custom_functions.py., e.g.:</p>
  
  <pre><code># This is the proposed custom_functions.py
  def create_df():
     return pd.DataFrame({'a': [1, 2, 3]})
  
  def create_array():
     return np.array([1, 2, 3])
  </code></pre>
  
  <p>and</p>
  
  <pre><code># This is the proposed main.py
  import numpy as np
  from custom_functions import create_array
  </code></pre>
  
  <p>The above code throws an error (<code>NameError: name "np" is not defined</code>). Is the only solution to break custom_functions.py into separate scripts and just load all associated libraries every time I load custom_functions into main.py? </p>
  
  <p>In case it's helpful, I'm using Python 3.6.5 with Anaconda on a Windows 10 machine.</p>
  
  <p>Thanks for your help!</p>