code: def generate_safemode_windows():
      
  
      try:
          import pyblish
          import pyblish_qml
          import PyQt5
  
      except ImportError:
          return sys.stderr.write(
              "Run this in a terminal with access to "
              "the Pyblish libraries and PyQt5.\n")
  
      template = r"""@echo off
  
      :: Clear all environment variables
  
      @echo off
      if exist ".\backup_env.bat" del ".\backup_env.bat"
      for /f "tokens=1* delims==" %%a in ('set') do (
      echo set %%a=%%b>> .\backup_env.bat
      set %%a=
      )
  
      :: Set only the bare essentials
  
      set PATH={PyQt5}
      set PATH=%PATH%;{python}
      set PYTHONPATH={pyblish}
      set PYTHONPATH=%PYTHONPATH%;{pyblish_qml}
      set PYTHONPATH=%PYTHONPATH%;{PyQt5}
  
      set SystemRoot=C:\Windows
  
      :: Run Pyblish
  
      python -m pyblish_qml
  
      :: Restore environment
      backup_env.bat
  
      """
  
      values = {}
      for lib in (pyblish, pyblish_qml, PyQt5):
          values[lib.__name__] = os.path.dirname(os.path.dirname(lib.__file__))
  
      values["python"] = os.path.dirname(sys.executable)
  
      with open("run.bat", "w") as f:
          print("Writing %s" % template.format(**values))
          f.write(template.format(**values))
docs: Produce batch file to run QML in safe-mode
  
      Usage:
          $ python -c "import compat;compat.generate_safemode_windows()"
          $ run.bat