title: PyInstaller win32ctypes.pywin32.pywintypes.error: (2, 'LoadLibraryExW', 'The system cannot find the file specified.')
body: <p>While using PyInstaller (dev version 4.0.dev0+8196c57ab), produced an <code>OSError: [WinError 2] 'The system cannot find the file specified.'</code></p>
  
  <ul>
  <li>Python version: 3.7</li>
  <li>GUI: PySide2 5.13.0</li>
  <li>Other packages: lxml, BeautifulSoup, Matplotlib (with dependencies like numpy), Pandas, pypiwin32, reportlab, Theano</li>
  <li>Anaconda 3, Windows</li>
  <li>Compiled with PyInstaller --onedir</li>
  </ul>
  
  <p>What I've tried:</p>
  
  <ul>
  <li>Tried downgrading PyInstaller to 2.1 as suggested here: <a href="https://github.com/pyinstaller/pyinstaller/issues/3916" rel="noreferrer">https://github.com/pyinstaller/pyinstaller/issues/3916</a> but doesn't work as Python 3 is not supported</li>
  <li>Was originally on PyInstaller 3.5, upgraded to dev version as suggested under some of the issues on PyInstaller github</li>
  <li>Tried including <code>--exclude-module=.git</code></li>
  </ul>
  
  <pre><code>import PyInstaller.__main__
  
  if __name__ == '__main__':
      PyInstaller.__main__.run([
          '--name=%s' % 'Dummy App',
          '--onedir',
          '--nowindowed',
          r'--workpath=C:\Users\User1\Desktop\build7',
          r'--distpath=C:\Users\User1\Desktop\dist7',
          '--hidden-import=theano.tensor.shared_randomstreams',
          '--hidden-import=pandas._libs.tslibs.timedeltas',
          '--clean',
          '--add-data={0};.'.format('redacted.xml'),
          '--add-data={0};{0}'.format('redacted_folder'),
          '--add-data={0};.'.format('redacted.pdf'),
          '--exclude-module={0}'.format('.git'),
          '--log-level=WARN',
          'MainWindow.py'
      ])
  </code></pre>
  
  <p>Full stacktrace:</p>
  
  <pre><code>79702 DEBUG: Analyzing .git\objects\78\e83411cea88cd038acb12c005a984fc0d6d423
  Traceback (most recent call last):
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
      yield
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
      return _dll._LoadLibraryEx(fileName, 0, flags)
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\core\ctypes\_util.py", line 42, in check_null
      raise make_error(function, function_name)
  OSError: [WinError 2] The system cannot find the file specified.
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "C:/Users/User1/Dropbox/GitHub_Repos/DiabetesReportGenerator_v2/pyinstaller_freeze.py", line 37, in &lt;module&gt;
      'MainWindow.py'
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\__main__.py", line 112, in run
      run_build(pyi_config, spec_file, **vars(args))
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
      PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\build_main.py", line 732, in main
      build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\build_main.py", line 679, in build
      exec(code, spec_namespace)
    File "C:\Users\User1\Dropbox\GitHub_Repos\DiabetesReportGenerator_v2\Risk Calculator.spec", line 17, in &lt;module&gt;
      noarchive=False)
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
      self.__postinit__()
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
      self.assemble()
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\build_main.py", line 468, in assemble
      redirects=self.binding_redirects))
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\depend\bindepend.py", line 226, in Dependencies
      for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects):
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\depend\bindepend.py", line 402, in getAssemblyFiles
      for assembly in getAssemblies(pth):
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\depend\bindepend.py", line 353, in getAssemblies
      res = GetManifestResources(pth)
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", line 1005, in GetManifestResources
      return winresource.GetResources(filename, [RT_MANIFEST], names, languages)
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\utils\win32\winresource.py", line 168, in GetResources
      hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
      return _dll._LoadLibraryEx(fileName, 0, flags)
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\contextlib.py", line 130, in __exit__
      self.gen.throw(type, value, traceback)
    File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
      raise error(exception.winerror, exception.function, exception.strerror)
  win32ctypes.pywin32.pywintypes.error: (2, 'LoadLibraryExW', 'The system cannot find the file specified.')
  </code></pre>
  
  <p>P.S. Compilation and the exe functioned perfectly with virtualenv environment created from Anaconda environment earlier (without need for <code>--exclude-module=.git</code>), but was too bloated with packages because the virtualenv environment is still considered to be part of the conda environment. So I used a new conda environment, and this error appeared</p>
  
  <p>I've gotten it to work by creating another virtualenv environment in this new conda environment, but that is a very roundabout way. Is there any workaround?</p>