code: def base_uri(relative_path=''):
      
      try:
          # PyInstaller creates a temp folder and stores path in _MEIPASS
          base_path = sys._MEIPASS
      except Exception:
          if 'pytest' in sys.modules:
              for arg in reversed(sys.argv):
                  path = os.path.realpath(arg)
  
                  if os.path.exists(path):
                      base_path = path if os.path.isdir(path) else os.path.dirname(path)
                      break
          else:
              base_path = os.path.dirname(os.path.realpath(sys.argv[0]))
  
      if not os.path.exists(base_path):
          raise ValueError('Path %s does not exist' % base_path)
  
      return 'file://%s' % os.path.join(base_path, relative_path)
docs: Get absolute path to resource, works for dev and for PyInstaller