We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Not able to create mac executable if we have used PyautoGUI in python script
I am facing issue in pyinstaller if I try to make executable file from mac when I use pyautogui library in Python script(Working fine on windows).
After debugging I got to know that issue is when I use pyautogui and pyinstaller together.
So, I've tried this simple program which has just import of pyautogui
demo.py
```
import pyautogui as pg
if __name__ == "__main__":
    `print("Hello,` WOrld!")
```

It was giving me below error if I just type pyinstaller demo.py --onefile
exit;
Traceback (most recent call last):
  File "PyInstaller/hooks/rthooks/pyi_rth__tkinter.py", line 20, in <module>
FileNotFoundError: Tcl data directory "/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIyqvIJz/tcl" not found.
[57142] Failed to execute script pyi_rth__tkinter

So, I've tried this
pyinstaller --onefile --add-binary='/System/Library/Frameworks/Tk.framework/Tk':'tk' --add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl' demo.py

below is the stacktrace of error:

exit;
Traceback (most recent call last):
  File "PyInstaller/loader/pyiboot01_bootstrap.py", line 144, in __init__
  File "ctypes/__init__.py", line 348, in __init__
OSError: dlopen(/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIjmFz1e/Foundation, 6): no suitable image found.  Did find:
	/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIjmFz1e/Foundation: not a file
	/private/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIjmFz1e/Foundation: not a file

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "demo.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "/Users/admin/Documents/django_infoware/venv_demo/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "pyautogui/__init__.py", line 241, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "/Users/admin/Documents/django_infoware/venv_demo/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "mouseinfo/__init__.py", line 100, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "/Users/admin/Documents/django_infoware/venv_demo/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "rubicon/objc/__init__.py", line 15, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "/Users/admin/Documents/django_infoware/venv_demo/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "rubicon/objc/runtime.py", line 81, in <module>
  File "rubicon/objc/runtime.py", line 58, in load_library
  File "PyInstaller/loader/pyiboot01_bootstrap.py", line 146, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll '/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIjmFz1e/Foundation'. Most probably this dynlib/dll was not found when the application was frozen.
[57474] Failed to execute script demo

[Process completed]

It seems like there is some windows dependency when I use pyautoGUI. Even I am on mac



--- 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-2020, PyInstaller Development Team.
3 #
4 # Distributed under the terms of the GNU General Public License (version 2
5 # or later) with exception for distributing the bootloader.
6 #
7 # The full license is in the file COPYING.txt, distributed with this software.
8 #
9 # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
10 #-----------------------------------------------------------------------------
11 
12 
13 ### Start bootstrap process
14 # Only python built-in modules can be used.
15 
16 import sys
17 import pyimod03_importers
18 
19 # Extend Python import machinery by adding PEP302 importers to sys.meta_path.
20 pyimod03_importers.install()
21 
22 
23 ### Bootstrap process is complete.
24 # We can use other python modules (e.g. os)
25 
26 
27 import os
28 
29 
30 # Let other python modules know that the code is running in frozen mode.
31 if not hasattr(sys, 'frozen'):
32     sys.frozen = True
33 
34 # sys._MEIPASS is now set in the bootloader. Hooray.
35 
36 
37 # Python 3 C-API function Py_SetPath() resets sys.prefix to empty string.
38 # Python 2 was using PYTHONHOME for sys.prefix. Let's do the same for Python 3.
39 sys.prefix = sys._MEIPASS
40 sys.exec_prefix = sys.prefix
41 
42 
43 # Python 3.3+ defines also sys.base_prefix. Let's set them too.
44 sys.base_prefix = sys.prefix
45 sys.base_exec_prefix = sys.exec_prefix
46 
47 
48 # Some packages behaves differently when running inside virtual environment.
49 # E.g. IPython tries to append path VIRTUAL_ENV to sys.path.
50 # For the frozen app we want to prevent this behavior.
51 VIRTENV = 'VIRTUAL_ENV'
52 if VIRTENV in os.environ:
53     # On some platforms (e.g. AIX) 'os.unsetenv()' is not available and then
54     # deleting the var from os.environ does not delete it from the environment.
55     os.environ[VIRTENV] = ''
56     del os.environ[VIRTENV]
57 
58 
59 # Ensure sys.path contains absolute paths. Otherwise import of other python
60 # modules will fail when current working directory is changed by frozen
61 # application.
62 python_path = []
63 for pth in sys.path:
64     python_path.append(os.path.abspath(pth))
65     sys.path = python_path
66 
67 
68 # Implement workaround for prints in non-console mode. In non-console mode
69 # (with "pythonw"), print randomly fails with "[errno 9] Bad file descriptor"
70 # when the printed text is flushed (eg: buffer full); this is because the
71 # sys.stdout object is bound to an invalid file descriptor.
72 # Python 3000 has a fix for it (http://bugs.python.org/issue1415), but we
73 # feel that a workaround in PyInstaller is a good thing since most people
74 # found this problem for the first time with PyInstaller as they don't
75 # usually run their code with "pythonw" (and it's hard to debug anyway).
76 class NullWriter:
77     softspace = 0
78     encoding = 'UTF-8'
79 
80     def write(*args):
81         pass
82 
83     def flush(*args):
84         pass
85 
86     # Some packages are checking if stdout/stderr is available.
87     # e.g. youtube-dl  for details see #1883
88     def isatty(self):
89         return False
90 
91 
92 # sys.stdout/err is None in GUI mode on Windows.
93 if sys.stdout is None:
94     sys.stdout = NullWriter()
95 if sys.stderr is None:
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) from base_error
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) from base_error
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) from base_error
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) from base_error
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
@@ -126,7 +126,7 @@
     def _frozen_name(name):
         if name:
             frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))
-            if os.path.exists(frozen_name):
+            if os.path.exists(frozen_name) and not os.path.isdir(frozen_name):
                 name = frozen_name
         return name

{"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@@ -126,7 +126,7 @@\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+            if os.path.exists(frozen_name) and not os.path.isdir(frozen_name):\n                 name = frozen_name\n         return name\n", "issue": "Not able to create mac executable if we have used PyautoGUI in python script\nI am facing issue in pyinstaller if I try to make executable file from mac when I use pyautogui library in Python script(Working fine on windows).\r\nAfter debugging I got to know that issue is when I use pyautogui and pyinstaller together.\r\nSo, I've tried this simple program which has just import of pyautogui\r\ndemo.py\r\n```\r\nimport pyautogui as pg\r\nif __name__ == \"__main__\":\r\n    `print(\"Hello,` WOrld!\")\r\n```\r\n\r\nIt was giving me below error if I just type pyinstaller demo.py --onefile\r\nexit;\r\nTraceback (most recent call last):\r\n  File \"PyInstaller/hooks/rthooks/pyi_rth__tkinter.py\", line 20, in <module>\r\nFileNotFoundError: Tcl data directory \"/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIyqvIJz/tcl\" not found.\r\n[57142] Failed to execute script pyi_rth__tkinter\r\n\r\nSo, I've tried this\r\npyinstaller --onefile --add-binary='/System/Library/Frameworks/Tk.framework/Tk':'tk' --add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl' demo.py\r\n\r\nbelow is the stacktrace of error:\r\n\r\nexit;\r\nTraceback (most recent call last):\r\n  File \"PyInstaller/loader/pyiboot01_bootstrap.py\", line 144, in __init__\r\n  File \"ctypes/__init__.py\", line 348, in __init__\r\nOSError: dlopen(/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIjmFz1e/Foundation, 6): no suitable image found.  Did find:\r\n\t/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIjmFz1e/Foundation: not a file\r\n\t/private/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIjmFz1e/Foundation: not a file\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"demo.py\", line 1, in <module>\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 955, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 665, in _load_unlocked\r\n  File \"/Users/admin/Documents/django_infoware/venv_demo/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py\", line 493, in exec_module\r\n    exec(bytecode, module.__dict__)\r\n  File \"pyautogui/__init__.py\", line 241, in <module>\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 955, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 665, in _load_unlocked\r\n  File \"/Users/admin/Documents/django_infoware/venv_demo/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py\", line 493, in exec_module\r\n    exec(bytecode, module.__dict__)\r\n  File \"mouseinfo/__init__.py\", line 100, in <module>\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 955, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 665, in _load_unlocked\r\n  File \"/Users/admin/Documents/django_infoware/venv_demo/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py\", line 493, in exec_module\r\n    exec(bytecode, module.__dict__)\r\n  File \"rubicon/objc/__init__.py\", line 15, in <module>\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 955, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 665, in _load_unlocked\r\n  File \"/Users/admin/Documents/django_infoware/venv_demo/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py\", line 493, in exec_module\r\n    exec(bytecode, module.__dict__)\r\n  File \"rubicon/objc/runtime.py\", line 81, in <module>\r\n  File \"rubicon/objc/runtime.py\", line 58, in load_library\r\n  File \"PyInstaller/loader/pyiboot01_bootstrap.py\", line 146, in __init__\r\n__main__.PyInstallerImportError: Failed to load dynlib/dll '/var/folders/83/vlr93lcs4bg1r6ytzy1vvjy40000gn/T/_MEIjmFz1e/Foundation'. Most probably this dynlib/dll was not found when the application was frozen.\r\n[57474] Failed to execute script demo\r\n\r\n[Process completed]\r\n\r\nIt seems like there is some windows dependency when I use pyautoGUI. Even I am on mac\r\n\r\n\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2005-2020, PyInstaller Development Team.\n#\n# Distributed under the terms of the GNU General Public License (version 2\n# or later) with exception for distributing the bootloader.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#\n# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)\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.\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# sys.stdout/err is None in GUI mode on Windows.\nif sys.stdout is None:\n    sys.stdout = NullWriter()\nif sys.stderr is None:\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) from base_error\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) from base_error\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) from base_error\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) from base_error\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-2020, PyInstaller Development Team.\n#\n# Distributed under the terms of the GNU General Public License (version 2\n# or later) with exception for distributing the bootloader.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#\n# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)\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.\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# sys.stdout/err is None in GUI mode on Windows.\nif sys.stdout is None:\n    sys.stdout = NullWriter()\nif sys.stderr is None:\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) and not os.path.isdir(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) from base_error\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) from base_error\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) from base_error\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) from base_error\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"}]}