I'm trying to use the following function:
def image_from_url(url):
    """
    Read an image from a URL. Returns a numpy array with the pixel data.
    We write the image to a temporary file then read it back. Kinda gross.
    """
    try:
        f = urllib.request.urlopen(url)
        _, fname = tempfile.mkstemp()
        with open(fname, 'wb') as ff:
            ff.write(f.read())
        img = imread(fname)
        os.remove(fname)
        return img
    except urllib.error.URLError as e:
        print('URL Error: ', e.reason, url)
    except urllib.error.HTTPError as e:
        print('HTTP Error: ', e.code, url)
But I keep on getting the following error:
---> 67         os.remove(fname)
     68         return img
     69     except urllib.error.URLError as e:
     PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\Nir\\AppData\\Local\\Temp\\tmp8p_pmso5'
No other processes are running on my machine (as far as I know).  If I leave out the os.remove(fname) function, then the code works well, but I don't want my temp folder to fill up with garbage.
Any idea what is keeping the image from being deleted?
 
     
     
    