We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
win32: multibyte path bootloader import issue with python2 
OS: windows 7/windows 10
Py: Python 2.7.13
Pyinstaller: Pyinstaller 3.3-dev 964547c

tl;dr the pyinstaller one-file failed to proper import during bootloader stage when the path involve multibyte character under win32 py2,

1. create a username with multibyte character, `許功蓋` is most suitable one for this as it contain special character

2. install some package that make bootloader do some import
`pip install pypiwin32`

3. sample script for pyinstaller to start with
`broken_py2_path.py`
```
# -*- coding: utf-8 -*-

import pywintypes

def main():
	pass
	
if __name__ == '__main__':
	main()
```

4. bundle it
`pyinstaller -F -d broken_py2_path.py`

5. execute `broken_py2_path.exe`

6. bam
```
E:\新增資料夾>broken_py2_path.exe
PyInstaller Bootloader 3.x
LOADER: executable is E:\?啣?鞈?憭閱broken_py2_path.exe
LOADER: homepath is E:\?啣?鞈?憭?
LOADER: _MEIPASS2 is NULL
LOADER: archivename is E:\?啣?鞈?憭閱broken_py2_path.exe
LOADER: Extracting binaries
LOADER: Executing self as child
LOADER: set _MEIPASS2 to C:\Users\閮勗??AppData\Local\Temp\_MEI143282
LOADER: Setting up to run child
LOADER: Creating child process
LOADER: Waiting for child process to finish...
PyInstaller Bootloader 3.x
LOADER: executable is E:\?啣?鞈?憭閱broken_py2_path.exe
LOADER: homepath is E:\?啣?鞈?憭?
LOADER: _MEIPASS2 is C:\Users\閮勗??AppData\Local\Temp\_MEI143282
LOADER: archivename is E:\?啣?鞈?憭閱broken_py2_path.exe
LOADER: SetDllDirectory(C:\Users\閮勗??AppData\Local\Temp\_MEI143282)
LOADER: Already in the child - running user's code.
LOADER: manifestpath: C:\Users\閮勗??AppData\Local\Temp\_MEI143282\broken_py2_path.exe.manifest
LOADER: Activation context created
LOADER: Activation context activated
LOADER: Python library: C:\Users\閮勗??AppData\Local\Temp\_MEI143282\python27.dll
LOADER: Loaded functions from Python library.
LOADER: Manipulating environment (sys.path, sys.prefix)
LOADER: sys.prefix is C:\Users\許功蓋\AppData\Local\Temp\_MEI14~1
LOADER: Setting runtime options
LOADER: Bootloader option: pyi-windows-manifest-filename broken_py2_path.exe.manifest
LOADER: Initializing python
LOADER: Overriding Python's sys.path
LOADER: Post-init sys.path is C:\Users\閮勗??AppData\Local\Temp\_MEI143282
LOADER: Setting sys.argv
LOADER: setting sys._MEIPASS
LOADER: importing modules from CArchive
LOADER: extracted struct
LOADER: callfunction returned...
LOADER: extracted pyimod01_os_path
LOADER: callfunction returned...
LOADER: extracted pyimod02_archive
LOADER: callfunction returned...
LOADER: extracted pyimod03_importers
LOADER: callfunction returned...
LOADER: Installing PYZ archive with Python modules.
LOADER: PYZ archive: out00-PYZ.pyz
LOADER: Running pyiboot01_bootstrap.py
LOADER: Running broken_py2_path.py
Traceback (most recent call last):
  File "broken_py2_path.py", line 3, in <module>
  File "d:\andcycle\documents\work\corelight\proj\poc\runtime\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
  File "site-packages\win32\lib\pywintypes.py", line 124, in <module>
  File "site-packages\win32\lib\pywintypes.py", line 61, in __import_pywin32_system_module__
ImportError: Module 'pywintypes' isn't in frozen sys.path ['C:\\Users\\\xb3\\\xa5\\\xbb\\AppData\\Local\\Temp\\_MEI14~1']
Failed to execute script broken_py2_path
LOADER: OK.
LOADER: Cleaning up Python interpreter.
LOADER: Back to parent (RC: -1)
LOADER: Doing cleanup
LOADER: Freeing archive status for E:\?啣?鞈?憭閱broken_py2_path.exe

E:\新增資料夾>
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `PyInstaller/loader/pyiboot01_bootstrap.py`
Content:
```
1 #-----------------------------------------------------------------------------
2 # Copyright (c) 2005-2017, PyInstaller Development Team.
3 #
4 # Distributed under the terms of the GNU General Public License with exception
5 # for distributing bootloader.
6 #
7 # The full license is in the file COPYING.txt, distributed with this software.
8 #-----------------------------------------------------------------------------
9 
10 
11 ### Start bootstrap process
12 # Only python built-in modules can be used.
13 
14 import sys
15 import pyimod03_importers
16 
17 # Extend Python import machinery by adding PEP302 importers to sys.meta_path.
18 pyimod03_importers.install()
19 
20 
21 ### Bootstrap process is complete.
22 # We can use other python modules (e.g. os)
23 
24 
25 import os
26 
27 
28 # Let other python modules know that the code is running in frozen mode.
29 if not hasattr(sys, 'frozen'):
30     sys.frozen = True
31 
32 # sys._MEIPASS is now set in the bootloader. Hooray.
33 
34 
35 # Python 3 C-API function Py_SetPath() resets sys.prefix to empty string.
36 # Python 2 was using PYTHONHOME for sys.prefix. Let's do the same for Python 3.
37 sys.prefix = sys._MEIPASS
38 sys.exec_prefix = sys.prefix
39 
40 
41 # Python 3.3+ defines also sys.base_prefix. Let's set them too.
42 # TODO Do these variables does not hurt on Python 3.2 and 2.7?
43 sys.base_prefix = sys.prefix
44 sys.base_exec_prefix = sys.exec_prefix
45 
46 
47 # Some packages behaves differently when running inside virtual environment.
48 # E.g. IPython tries to append path VIRTUAL_ENV to sys.path.
49 # For the frozen app we want to prevent this behavior.
50 VIRTENV = 'VIRTUAL_ENV'
51 if VIRTENV in os.environ:
52     # On some platforms (e.g. AIX) 'os.unsetenv()' is not available and then
53     # deleting the var from os.environ does not delete it from the environment.
54     os.environ[VIRTENV] = ''
55     del os.environ[VIRTENV]
56 
57 
58 # Ensure sys.path contains absolute paths. Otherwise import of other python
59 # modules will fail when current working directory is changed by frozen
60 # application.
61 python_path = []
62 for pth in sys.path:
63     python_path.append(os.path.abspath(pth))
64     sys.path = python_path
65 
66 
67 # Implement workaround for prints in non-console mode. In non-console mode
68 # (with "pythonw"), print randomly fails with "[errno 9] Bad file descriptor"
69 # when the printed text is flushed (eg: buffer full); this is because the
70 # sys.stdout object is bound to an invalid file descriptor.
71 # Python 3000 has a fix for it (http://bugs.python.org/issue1415), but we
72 # feel that a workaround in PyInstaller is a good thing since most people
73 # found this problem for the first time with PyInstaller as they don't
74 # usually run their code with "pythonw" (and it's hard to debug anyway).
75 class NullWriter:
76     softspace = 0
77     encoding = 'UTF-8'
78 
79     def write(*args):
80         pass
81 
82     def flush(*args):
83         pass
84 
85     # Some packages are checking if stdout/stderr is available.
86     # e.g. youtube-dl  for details see #1883
87     def isatty(self):
88         return False
89 
90 
91 # In Python 3 sys.stdout/err is None in GUI mode on Windows.
92 # In Python 2 we need to check .fileno().
93 if sys.stdout is None or sys.stdout.fileno() < 0:
94     sys.stdout = NullWriter()
95 if sys.stderr is None or sys.stderr.fileno() < 0:
96     sys.stderr = NullWriter()
97 
98 
99 # At least on Windows, Python seems to hook up the codecs on this
100 # import, so it's not enough to just package up all the encodings.
101 #
102 # It was also reported that without 'encodings' module the frozen executable
103 # will fail to load in some configurations:
104 #
105 # http://www.pyinstaller.org/ticket/651
106 #
107 # Import 'encodings' module in a run-time hook is not enough since some
108 # run-time hooks require this module and the order of running code from
109 # from run-time hooks is not defined.
110 try:
111     import encodings
112 except ImportError:
113     pass
114 
115 
116 # In the Python interpreter 'warnings' module is imported when 'sys.warnoptions'
117 # is not empty. Mimic this behavior in PyInstaller.
118 if sys.warnoptions:
119     import warnings
120 
121 try:
122     import ctypes
123     import os
124     from ctypes import LibraryLoader, DEFAULT_MODE
125 
126     def _frozen_name(name):
127         if name:
128             frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))
129             if os.path.exists(frozen_name):
130                 name = frozen_name
131         return name
132 
133     class PyInstallerImportError(OSError):
134         def __init__(self, name):
135             self.msg = ("Failed to load dynlib/dll %r. "
136                         "Most probably this dynlib/dll was not found "
137                         "when the application was frozen.") % name
138             self.args = (self.msg,)
139 
140     class PyInstallerCDLL(ctypes.CDLL):
141         def __init__(self, name, *args, **kwargs):
142             name = _frozen_name(name)
143             try:
144                 super(PyInstallerCDLL, self).__init__(name, *args, **kwargs)
145             except Exception as base_error:
146                 raise PyInstallerImportError(name)
147 
148     ctypes.CDLL = PyInstallerCDLL
149     ctypes.cdll = LibraryLoader(PyInstallerCDLL)
150 
151     class PyInstallerPyDLL(ctypes.PyDLL):
152         def __init__(self, name, *args, **kwargs):
153             name = _frozen_name(name)
154             try:
155                 super(PyInstallerPyDLL, self).__init__(name, *args, **kwargs)
156             except Exception as base_error:
157                 raise PyInstallerImportError(name)
158 
159     ctypes.PyDLL = PyInstallerPyDLL
160     ctypes.pydll = LibraryLoader(PyInstallerPyDLL)
161 
162     if sys.platform.startswith('win'):
163         class PyInstallerWinDLL(ctypes.WinDLL):
164             def __init__(self, name,*args, **kwargs):
165                 name = _frozen_name(name)
166                 try:
167                     super(PyInstallerWinDLL, self).__init__(name, *args, **kwargs)
168                 except Exception as base_error:
169                     raise PyInstallerImportError(name)
170 
171         ctypes.WinDLL = PyInstallerWinDLL
172         ctypes.windll = LibraryLoader(PyInstallerWinDLL)
173 
174         class PyInstallerOleDLL(ctypes.OleDLL):
175             def __init__(self, name,*args, **kwargs):
176                 name = _frozen_name(name)
177                 try:
178                     super(PyInstallerOleDLL, self).__init__(name, *args, **kwargs)
179                 except Exception as base_error:
180                     raise PyInstallerImportError(name)
181 
182         ctypes.OleDLL = PyInstallerOleDLL
183         ctypes.oledll = LibraryLoader(PyInstallerOleDLL)
184 except ImportError:
185     pass
186 
187 # On Mac OS X insert sys._MEIPASS in the first position of the list of paths
188 # that ctypes uses to search for libraries.
189 #
190 # Note: 'ctypes' module will NOT be bundled with every app because code in this
191 #       module is not scanned for module dependencies. It is safe to wrap
192 #       'ctypes' module into 'try/except ImportError' block.
193 if sys.platform.startswith('darwin'):
194     try:
195         from ctypes.macholib import dyld
196         dyld.DEFAULT_LIBRARY_FALLBACK.insert(0, sys._MEIPASS)
197     except ImportError:
198         # Do nothing when module 'ctypes' is not available.
199         pass
200 
201 
202 # Make .eggs and zipfiles available at runtime
203 d = "eggs"
204 d = os.path.join(sys._MEIPASS, d)
205 # Test if the 'eggs' directory exists. This allows to
206 # opportunistically including this script into the packaged exe, even
207 # if no eggs as found when packaging the program. (Which may be a
208 # use-case, see issue #653.
209 if os.path.isdir(d):
210     for fn in os.listdir(d):
211         sys.path.append(os.path.join(d, fn))
212
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/PyInstaller/loader/pyiboot01_bootstrap.py b/PyInstaller/loader/pyiboot01_bootstrap.py
--- a/PyInstaller/loader/pyiboot01_bootstrap.py
+++ b/PyInstaller/loader/pyiboot01_bootstrap.py
@@ -60,7 +60,12 @@
 # application.
 python_path = []
 for pth in sys.path:
-    python_path.append(os.path.abspath(pth))
+    if not os.path.isabs(pth):
+        # careful about using abspath with non-unicode path,
+        # it breaks multibyte character that contain slash under win32/Python 2
+        # TODO: Revert when dropping suport for is_py2.
+        pth = os.path.abspath(pth)
+    python_path.append(pth)
     sys.path = python_path

{"golden_diff": "diff --git a/PyInstaller/loader/pyiboot01_bootstrap.py b/PyInstaller/loader/pyiboot01_bootstrap.py\n--- a/PyInstaller/loader/pyiboot01_bootstrap.py\n+++ b/PyInstaller/loader/pyiboot01_bootstrap.py\n@@ -60,7 +60,12 @@\n # application.\n python_path = []\n for pth in sys.path:\n-    python_path.append(os.path.abspath(pth))\n+    if not os.path.isabs(pth):\n+        # careful about using abspath with non-unicode path,\n+        # it breaks multibyte character that contain slash under win32/Python 2\n+        # TODO: Revert when dropping suport for is_py2.\n+        pth = os.path.abspath(pth)\n+    python_path.append(pth)\n     sys.path = python_path\n", "issue": "win32: multibyte path bootloader import issue with python2 \nOS: windows 7/windows 10\r\nPy: Python 2.7.13\r\nPyinstaller: Pyinstaller 3.3-dev 964547c\r\n\r\ntl;dr the pyinstaller one-file failed to proper import during bootloader stage when the path involve multibyte character under win32 py2,\r\n\r\n1. create a username with multibyte character, `\u8a31\u529f\u84cb` is most suitable one for this as it contain special character\r\n\r\n2. install some package that make bootloader do some import\r\n`pip install pypiwin32`\r\n\r\n3. sample script for pyinstaller to start with\r\n`broken_py2_path.py`\r\n```\r\n# -*- coding: utf-8 -*-\r\n\r\nimport pywintypes\r\n\r\ndef main():\r\n\tpass\r\n\t\r\nif __name__ == '__main__':\r\n\tmain()\r\n```\r\n\r\n4. bundle it\r\n`pyinstaller -F -d broken_py2_path.py`\r\n\r\n5. execute `broken_py2_path.exe`\r\n\r\n6. bam\r\n```\r\nE:\\\u65b0\u589e\u8cc7\u6599\u593e>broken_py2_path.exe\r\nPyInstaller Bootloader 3.x\r\nLOADER: executable is E:\\?\u5563?\u9788\uf2ea?\u61ad\u95b1broken_py2_path.exe\r\nLOADER: homepath is E:\\?\u5563?\u9788\uf2ea?\u61ad?\r\nLOADER: _MEIPASS2 is NULL\r\nLOADER: archivename is E:\\?\u5563?\u9788\uf2ea?\u61ad\u95b1broken_py2_path.exe\r\nLOADER: Extracting binaries\r\nLOADER: Executing self as child\r\nLOADER: set _MEIPASS2 to C:\\Users\\\u95ae\u52d7??\uf4f6AppData\\Local\\Temp\\_MEI143282\r\nLOADER: Setting up to run child\r\nLOADER: Creating child process\r\nLOADER: Waiting for child process to finish...\r\nPyInstaller Bootloader 3.x\r\nLOADER: executable is E:\\?\u5563?\u9788\uf2ea?\u61ad\u95b1broken_py2_path.exe\r\nLOADER: homepath is E:\\?\u5563?\u9788\uf2ea?\u61ad?\r\nLOADER: _MEIPASS2 is C:\\Users\\\u95ae\u52d7??\uf4f6AppData\\Local\\Temp\\_MEI143282\r\nLOADER: archivename is E:\\?\u5563?\u9788\uf2ea?\u61ad\u95b1broken_py2_path.exe\r\nLOADER: SetDllDirectory(C:\\Users\\\u95ae\u52d7??\uf4f6AppData\\Local\\Temp\\_MEI143282)\r\nLOADER: Already in the child - running user's code.\r\nLOADER: manifestpath: C:\\Users\\\u95ae\u52d7??\uf4f6AppData\\Local\\Temp\\_MEI143282\\broken_py2_path.exe.manifest\r\nLOADER: Activation context created\r\nLOADER: Activation context activated\r\nLOADER: Python library: C:\\Users\\\u95ae\u52d7??\uf4f6AppData\\Local\\Temp\\_MEI143282\\python27.dll\r\nLOADER: Loaded functions from Python library.\r\nLOADER: Manipulating environment (sys.path, sys.prefix)\r\nLOADER: sys.prefix is C:\\Users\\\u8a31\u529f\u84cb\\AppData\\Local\\Temp\\_MEI14~1\r\nLOADER: Setting runtime options\r\nLOADER: Bootloader option: pyi-windows-manifest-filename broken_py2_path.exe.manifest\r\nLOADER: Initializing python\r\nLOADER: Overriding Python's sys.path\r\nLOADER: Post-init sys.path is C:\\Users\\\u95ae\u52d7??\uf4f6AppData\\Local\\Temp\\_MEI143282\r\nLOADER: Setting sys.argv\r\nLOADER: setting sys._MEIPASS\r\nLOADER: importing modules from CArchive\r\nLOADER: extracted struct\r\nLOADER: callfunction returned...\r\nLOADER: extracted pyimod01_os_path\r\nLOADER: callfunction returned...\r\nLOADER: extracted pyimod02_archive\r\nLOADER: callfunction returned...\r\nLOADER: extracted pyimod03_importers\r\nLOADER: callfunction returned...\r\nLOADER: Installing PYZ archive with Python modules.\r\nLOADER: PYZ archive: out00-PYZ.pyz\r\nLOADER: Running pyiboot01_bootstrap.py\r\nLOADER: Running broken_py2_path.py\r\nTraceback (most recent call last):\r\n  File \"broken_py2_path.py\", line 3, in <module>\r\n  File \"d:\\andcycle\\documents\\work\\corelight\\proj\\poc\\runtime\\Lib\\site-packages\\PyInstaller\\loader\\pyimod03_importers.py\", line 396, in load_module\r\n  File \"site-packages\\win32\\lib\\pywintypes.py\", line 124, in <module>\r\n  File \"site-packages\\win32\\lib\\pywintypes.py\", line 61, in __import_pywin32_system_module__\r\nImportError: Module 'pywintypes' isn't in frozen sys.path ['C:\\\\Users\\\\\\xb3\\\\\\xa5\\\\\\xbb\\\\AppData\\\\Local\\\\Temp\\\\_MEI14~1']\r\nFailed to execute script broken_py2_path\r\nLOADER: OK.\r\nLOADER: Cleaning up Python interpreter.\r\nLOADER: Back to parent (RC: -1)\r\nLOADER: Doing cleanup\r\nLOADER: Freeing archive status for E:\\?\u5563?\u9788\uf2ea?\u61ad\u95b1broken_py2_path.exe\r\n\r\nE:\\\u65b0\u589e\u8cc7\u6599\u593e>\r\n```\r\n\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2005-2017, PyInstaller Development Team.\n#\n# Distributed under the terms of the GNU General Public License with exception\n# for distributing bootloader.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n\n\n### Start bootstrap process\n# Only python built-in modules can be used.\n\nimport sys\nimport pyimod03_importers\n\n# Extend Python import machinery by adding PEP302 importers to sys.meta_path.\npyimod03_importers.install()\n\n\n### Bootstrap process is complete.\n# We can use other python modules (e.g. os)\n\n\nimport os\n\n\n# Let other python modules know that the code is running in frozen mode.\nif not hasattr(sys, 'frozen'):\n    sys.frozen = True\n\n# sys._MEIPASS is now set in the bootloader. Hooray.\n\n\n# Python 3 C-API function Py_SetPath() resets sys.prefix to empty string.\n# Python 2 was using PYTHONHOME for sys.prefix. Let's do the same for Python 3.\nsys.prefix = sys._MEIPASS\nsys.exec_prefix = sys.prefix\n\n\n# Python 3.3+ defines also sys.base_prefix. Let's set them too.\n# TODO Do these variables does not hurt on Python 3.2 and 2.7?\nsys.base_prefix = sys.prefix\nsys.base_exec_prefix = sys.exec_prefix\n\n\n# Some packages behaves differently when running inside virtual environment.\n# E.g. IPython tries to append path VIRTUAL_ENV to sys.path.\n# For the frozen app we want to prevent this behavior.\nVIRTENV = 'VIRTUAL_ENV'\nif VIRTENV in os.environ:\n    # On some platforms (e.g. AIX) 'os.unsetenv()' is not available and then\n    # deleting the var from os.environ does not delete it from the environment.\n    os.environ[VIRTENV] = ''\n    del os.environ[VIRTENV]\n\n\n# Ensure sys.path contains absolute paths. Otherwise import of other python\n# modules will fail when current working directory is changed by frozen\n# application.\npython_path = []\nfor pth in sys.path:\n    python_path.append(os.path.abspath(pth))\n    sys.path = python_path\n\n\n# Implement workaround for prints in non-console mode. In non-console mode\n# (with \"pythonw\"), print randomly fails with \"[errno 9] Bad file descriptor\"\n# when the printed text is flushed (eg: buffer full); this is because the\n# sys.stdout object is bound to an invalid file descriptor.\n# Python 3000 has a fix for it (http://bugs.python.org/issue1415), but we\n# feel that a workaround in PyInstaller is a good thing since most people\n# found this problem for the first time with PyInstaller as they don't\n# usually run their code with \"pythonw\" (and it's hard to debug anyway).\nclass NullWriter:\n    softspace = 0\n    encoding = 'UTF-8'\n\n    def write(*args):\n        pass\n\n    def flush(*args):\n        pass\n\n    # Some packages are checking if stdout/stderr is available.\n    # e.g. youtube-dl  for details see #1883\n    def isatty(self):\n        return False\n\n\n# In Python 3 sys.stdout/err is None in GUI mode on Windows.\n# In Python 2 we need to check .fileno().\nif sys.stdout is None or sys.stdout.fileno() < 0:\n    sys.stdout = NullWriter()\nif sys.stderr is None or sys.stderr.fileno() < 0:\n    sys.stderr = NullWriter()\n\n\n# At least on Windows, Python seems to hook up the codecs on this\n# import, so it's not enough to just package up all the encodings.\n#\n# It was also reported that without 'encodings' module the frozen executable\n# will fail to load in some configurations:\n#\n# http://www.pyinstaller.org/ticket/651\n#\n# Import 'encodings' module in a run-time hook is not enough since some\n# run-time hooks require this module and the order of running code from\n# from run-time hooks is not defined.\ntry:\n    import encodings\nexcept ImportError:\n    pass\n\n\n# In the Python interpreter 'warnings' module is imported when 'sys.warnoptions'\n# is not empty. Mimic this behavior in PyInstaller.\nif sys.warnoptions:\n    import warnings\n\ntry:\n    import ctypes\n    import os\n    from ctypes import LibraryLoader, DEFAULT_MODE\n\n    def _frozen_name(name):\n        if name:\n            frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))\n            if os.path.exists(frozen_name):\n                name = frozen_name\n        return name\n\n    class PyInstallerImportError(OSError):\n        def __init__(self, name):\n            self.msg = (\"Failed to load dynlib/dll %r. \"\n                        \"Most probably this dynlib/dll was not found \"\n                        \"when the application was frozen.\") % name\n            self.args = (self.msg,)\n\n    class PyInstallerCDLL(ctypes.CDLL):\n        def __init__(self, name, *args, **kwargs):\n            name = _frozen_name(name)\n            try:\n                super(PyInstallerCDLL, self).__init__(name, *args, **kwargs)\n            except Exception as base_error:\n                raise PyInstallerImportError(name)\n\n    ctypes.CDLL = PyInstallerCDLL\n    ctypes.cdll = LibraryLoader(PyInstallerCDLL)\n\n    class PyInstallerPyDLL(ctypes.PyDLL):\n        def __init__(self, name, *args, **kwargs):\n            name = _frozen_name(name)\n            try:\n                super(PyInstallerPyDLL, self).__init__(name, *args, **kwargs)\n            except Exception as base_error:\n                raise PyInstallerImportError(name)\n\n    ctypes.PyDLL = PyInstallerPyDLL\n    ctypes.pydll = LibraryLoader(PyInstallerPyDLL)\n\n    if sys.platform.startswith('win'):\n        class PyInstallerWinDLL(ctypes.WinDLL):\n            def __init__(self, name,*args, **kwargs):\n                name = _frozen_name(name)\n                try:\n                    super(PyInstallerWinDLL, self).__init__(name, *args, **kwargs)\n                except Exception as base_error:\n                    raise PyInstallerImportError(name)\n\n        ctypes.WinDLL = PyInstallerWinDLL\n        ctypes.windll = LibraryLoader(PyInstallerWinDLL)\n\n        class PyInstallerOleDLL(ctypes.OleDLL):\n            def __init__(self, name,*args, **kwargs):\n                name = _frozen_name(name)\n                try:\n                    super(PyInstallerOleDLL, self).__init__(name, *args, **kwargs)\n                except Exception as base_error:\n                    raise PyInstallerImportError(name)\n\n        ctypes.OleDLL = PyInstallerOleDLL\n        ctypes.oledll = LibraryLoader(PyInstallerOleDLL)\nexcept ImportError:\n    pass\n\n# On Mac OS X insert sys._MEIPASS in the first position of the list of paths\n# that ctypes uses to search for libraries.\n#\n# Note: 'ctypes' module will NOT be bundled with every app because code in this\n#       module is not scanned for module dependencies. It is safe to wrap\n#       'ctypes' module into 'try/except ImportError' block.\nif sys.platform.startswith('darwin'):\n    try:\n        from ctypes.macholib import dyld\n        dyld.DEFAULT_LIBRARY_FALLBACK.insert(0, sys._MEIPASS)\n    except ImportError:\n        # Do nothing when module 'ctypes' is not available.\n        pass\n\n\n# Make .eggs and zipfiles available at runtime\nd = \"eggs\"\nd = os.path.join(sys._MEIPASS, d)\n# Test if the 'eggs' directory exists. This allows to\n# opportunistically including this script into the packaged exe, even\n# if no eggs as found when packaging the program. (Which may be a\n# use-case, see issue #653.\nif os.path.isdir(d):\n    for fn in os.listdir(d):\n        sys.path.append(os.path.join(d, fn))\n", "path": "PyInstaller/loader/pyiboot01_bootstrap.py"}], "after_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2005-2017, PyInstaller Development Team.\n#\n# Distributed under the terms of the GNU General Public License with exception\n# for distributing bootloader.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n\n\n### Start bootstrap process\n# Only python built-in modules can be used.\n\nimport sys\nimport pyimod03_importers\n\n# Extend Python import machinery by adding PEP302 importers to sys.meta_path.\npyimod03_importers.install()\n\n\n### Bootstrap process is complete.\n# We can use other python modules (e.g. os)\n\n\nimport os\n\n\n# Let other python modules know that the code is running in frozen mode.\nif not hasattr(sys, 'frozen'):\n    sys.frozen = True\n\n# sys._MEIPASS is now set in the bootloader. Hooray.\n\n\n# Python 3 C-API function Py_SetPath() resets sys.prefix to empty string.\n# Python 2 was using PYTHONHOME for sys.prefix. Let's do the same for Python 3.\nsys.prefix = sys._MEIPASS\nsys.exec_prefix = sys.prefix\n\n\n# Python 3.3+ defines also sys.base_prefix. Let's set them too.\n# TODO Do these variables does not hurt on Python 3.2 and 2.7?\nsys.base_prefix = sys.prefix\nsys.base_exec_prefix = sys.exec_prefix\n\n\n# Some packages behaves differently when running inside virtual environment.\n# E.g. IPython tries to append path VIRTUAL_ENV to sys.path.\n# For the frozen app we want to prevent this behavior.\nVIRTENV = 'VIRTUAL_ENV'\nif VIRTENV in os.environ:\n    # On some platforms (e.g. AIX) 'os.unsetenv()' is not available and then\n    # deleting the var from os.environ does not delete it from the environment.\n    os.environ[VIRTENV] = ''\n    del os.environ[VIRTENV]\n\n\n# Ensure sys.path contains absolute paths. Otherwise import of other python\n# modules will fail when current working directory is changed by frozen\n# application.\npython_path = []\nfor pth in sys.path:\n    if not os.path.isabs(pth):\n        # careful about using abspath with non-unicode path,\n        # it breaks multibyte character that contain slash under win32/Python 2\n        # TODO: Revert when dropping suport for is_py2.\n        pth = os.path.abspath(pth)\n    python_path.append(pth)\n    sys.path = python_path\n\n\n# Implement workaround for prints in non-console mode. In non-console mode\n# (with \"pythonw\"), print randomly fails with \"[errno 9] Bad file descriptor\"\n# when the printed text is flushed (eg: buffer full); this is because the\n# sys.stdout object is bound to an invalid file descriptor.\n# Python 3000 has a fix for it (http://bugs.python.org/issue1415), but we\n# feel that a workaround in PyInstaller is a good thing since most people\n# found this problem for the first time with PyInstaller as they don't\n# usually run their code with \"pythonw\" (and it's hard to debug anyway).\nclass NullWriter:\n    softspace = 0\n    encoding = 'UTF-8'\n\n    def write(*args):\n        pass\n\n    def flush(*args):\n        pass\n\n    # Some packages are checking if stdout/stderr is available.\n    # e.g. youtube-dl  for details see #1883\n    def isatty(self):\n        return False\n\n\n# In Python 3 sys.stdout/err is None in GUI mode on Windows.\n# In Python 2 we need to check .fileno().\nif sys.stdout is None or sys.stdout.fileno() < 0:\n    sys.stdout = NullWriter()\nif sys.stderr is None or sys.stderr.fileno() < 0:\n    sys.stderr = NullWriter()\n\n\n# At least on Windows, Python seems to hook up the codecs on this\n# import, so it's not enough to just package up all the encodings.\n#\n# It was also reported that without 'encodings' module the frozen executable\n# will fail to load in some configurations:\n#\n# http://www.pyinstaller.org/ticket/651\n#\n# Import 'encodings' module in a run-time hook is not enough since some\n# run-time hooks require this module and the order of running code from\n# from run-time hooks is not defined.\ntry:\n    import encodings\nexcept ImportError:\n    pass\n\n\n# In the Python interpreter 'warnings' module is imported when 'sys.warnoptions'\n# is not empty. Mimic this behavior in PyInstaller.\nif sys.warnoptions:\n    import warnings\n\ntry:\n    import ctypes\n    import os\n    from ctypes import LibraryLoader, DEFAULT_MODE\n\n    def _frozen_name(name):\n        if name:\n            frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))\n            if os.path.exists(frozen_name):\n                name = frozen_name\n        return name\n\n    class PyInstallerImportError(OSError):\n        def __init__(self, name):\n            self.msg = (\"Failed to load dynlib/dll %r. \"\n                        \"Most probably this dynlib/dll was not found \"\n                        \"when the application was frozen.\") % name\n            self.args = (self.msg,)\n\n    class PyInstallerCDLL(ctypes.CDLL):\n        def __init__(self, name, *args, **kwargs):\n            name = _frozen_name(name)\n            try:\n                super(PyInstallerCDLL, self).__init__(name, *args, **kwargs)\n            except Exception as base_error:\n                raise PyInstallerImportError(name)\n\n    ctypes.CDLL = PyInstallerCDLL\n    ctypes.cdll = LibraryLoader(PyInstallerCDLL)\n\n    class PyInstallerPyDLL(ctypes.PyDLL):\n        def __init__(self, name, *args, **kwargs):\n            name = _frozen_name(name)\n            try:\n                super(PyInstallerPyDLL, self).__init__(name, *args, **kwargs)\n            except Exception as base_error:\n                raise PyInstallerImportError(name)\n\n    ctypes.PyDLL = PyInstallerPyDLL\n    ctypes.pydll = LibraryLoader(PyInstallerPyDLL)\n\n    if sys.platform.startswith('win'):\n        class PyInstallerWinDLL(ctypes.WinDLL):\n            def __init__(self, name,*args, **kwargs):\n                name = _frozen_name(name)\n                try:\n                    super(PyInstallerWinDLL, self).__init__(name, *args, **kwargs)\n                except Exception as base_error:\n                    raise PyInstallerImportError(name)\n\n        ctypes.WinDLL = PyInstallerWinDLL\n        ctypes.windll = LibraryLoader(PyInstallerWinDLL)\n\n        class PyInstallerOleDLL(ctypes.OleDLL):\n            def __init__(self, name,*args, **kwargs):\n                name = _frozen_name(name)\n                try:\n                    super(PyInstallerOleDLL, self).__init__(name, *args, **kwargs)\n                except Exception as base_error:\n                    raise PyInstallerImportError(name)\n\n        ctypes.OleDLL = PyInstallerOleDLL\n        ctypes.oledll = LibraryLoader(PyInstallerOleDLL)\nexcept ImportError:\n    pass\n\n# On Mac OS X insert sys._MEIPASS in the first position of the list of paths\n# that ctypes uses to search for libraries.\n#\n# Note: 'ctypes' module will NOT be bundled with every app because code in this\n#       module is not scanned for module dependencies. It is safe to wrap\n#       'ctypes' module into 'try/except ImportError' block.\nif sys.platform.startswith('darwin'):\n    try:\n        from ctypes.macholib import dyld\n        dyld.DEFAULT_LIBRARY_FALLBACK.insert(0, sys._MEIPASS)\n    except ImportError:\n        # Do nothing when module 'ctypes' is not available.\n        pass\n\n\n# Make .eggs and zipfiles available at runtime\nd = \"eggs\"\nd = os.path.join(sys._MEIPASS, d)\n# Test if the 'eggs' directory exists. This allows to\n# opportunistically including this script into the packaged exe, even\n# if no eggs as found when packaging the program. (Which may be a\n# use-case, see issue #653.\nif os.path.isdir(d):\n    for fn in os.listdir(d):\n        sys.path.append(os.path.join(d, fn))\n", "path": "PyInstaller/loader/pyiboot01_bootstrap.py"}]}