title: Is there a way to import and run a function from another script in python that will import libraries for the current script
body: <p>For example I am trying to import this function &quot;load_modules() which is in a script called &quot;setup.py&quot; into another script using the code directly below.</p>
  <pre><code>   def load_modules():
          import cv2
          import numpy as np
          import pandas as pd
          from scipy import ndimage
          import os
          from matplotlib import pyplot as plt
          import matplotlib.image as mpimg
          import time
          import math
          import random
          from scipy.ndimage.interpolation import map_coordinates
          from scipy.ndimage.filters import gaussian_filter
  
      from setup import *
      load_modules()
      img = cv2.imread(&quot;image.jpg&quot;, 1)
  </code></pre>
  <p>The first two lines run fine so the files functions have been imported and there appears to be no issue running the load_modules() function however I get an error on the last line saying that cv2 is not defined.</p>