title: Python file delete PermissionError: [WinError 32]
body: <p>I am trying to delete a duplicated image by comparing md5 file hash.</p>
  
  <p>my code is</p>
  
  <pre><code>from PIL import Image
  import hashlib
  import os
  import sys
  import io
  
  
  img_file = urllib.request.urlopen(img_url, timeout=30)
  f = open('C:\\Users\\user\\Documents\\ + img_name, 'wb')
  f.write(img_file.read())
  f.close   # subject image, status = ok
  
  im = Image.open('C:\\Users\\user\\Documents\\ + img_name)
  m = hashlib.md5()                # get hash
  with io.BytesIO() as memf:
      im.save(memf, 'PNG')
      data = memf.getvalue()
      m.update(data)
      md5hash = m.hexdigest()     # hash done, status = ok
  im.close()
  
  if md5hash in hash_list[name]:   # comparing hash
      os.remove('C:\\Users\\user\\Documents\\ + img_name) # delete file, ERROR
  else:
      hash_list[name].append(m.hexdigest())
  </code></pre>
  
  <p>and i get this error</p>
  
  <pre><code>PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:
  'C:\\Users\\user\\Documents\\myimage.jpg'
  </code></pre>
  
  <p>I tried admin command prompt, but still getting this error. Could you find what is accessing the file?</p>