prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  distutils not included with latest virtualenv (16.4.0)
  This was already reported in #4031. The issue was closed without a fix so I'm creating this one.
  
  **With virtualenv 16.4.0, pyinstaller reports :**
  
  ```
  3583 INFO: distutils: retargeting to non-venv dir '/usr/lib64/python3.6/distutils/__init__.py'
  ```
  and then during "Loading module hook" sequence, the `hook-distutils.py` is missing and distutils modules are not included into the final executable binary.
  
  When executing the binary the error is:
  
  ```
  ModuleNotFoundError: No module named 'distutils'
  [10373] Failed to execute script <name here>
  ```
  
  **With virtualenv 16.1.0, pyinstaller reports :**
  
  ```
  3157 INFO: Processing pre-find module path hook   distutils
  5053 INFO: Loading module hook "hook-distutils.py"...
  ```
  
  and distutils modules are included into the final executable binary.
  
  
  --- 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/hooks/pre_find_module_path/hook-distutils.py`
  Content:
  ```
  1 #-----------------------------------------------------------------------------
  2 # Copyright (c) 2005-2019, 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 `distutils`-specific pre-find module path hook.
  12 
  13 When run from within a venv (virtual environment), this hook changes the
  14 `__path__` of the `distutils` package to that of the system-wide rather than
  15 venv-specific `distutils` package. While the former is suitable for freezing,
  16 the latter is intended for use _only_ from within venvs.
  17 """
  18 
  19 
  20 import distutils
  21 import os
  22 
  23 from PyInstaller.utils.hooks import logger
  24 
  25 
  26 def pre_find_module_path(api):
  27     # Absolute path of the system-wide "distutils" package when run from within
  28     # a venv or None otherwise.
  29     distutils_dir = getattr(distutils, 'distutils_path', None)
  30     if distutils_dir is not None:
  31         # Find this package in its parent directory.
  32         api.search_dirs = [os.path.dirname(distutils_dir)]
  33         logger.info('distutils: retargeting to non-venv dir %r' % distutils_dir)
  34
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/PyInstaller/hooks/pre_find_module_path/hook-distutils.py b/PyInstaller/hooks/pre_find_module_path/hook-distutils.py
  --- a/PyInstaller/hooks/pre_find_module_path/hook-distutils.py
  +++ b/PyInstaller/hooks/pre_find_module_path/hook-distutils.py
  @@ -1,11 +1,11 @@
  -#-----------------------------------------------------------------------------
  +# -----------------------------------------------------------------------------
   # Copyright (c) 2005-2019, PyInstaller Development Team.
   #
   # Distributed under the terms of the GNU General Public License with exception
   # for distributing bootloader.
   #
   # The full license is in the file COPYING.txt, distributed with this software.
  -#-----------------------------------------------------------------------------
  +# -----------------------------------------------------------------------------
   
   """
   `distutils`-specific pre-find module path hook.
  @@ -26,8 +26,16 @@
   def pre_find_module_path(api):
       # Absolute path of the system-wide "distutils" package when run from within
       # a venv or None otherwise.
  -    distutils_dir = getattr(distutils, 'distutils_path', None)
  -    if distutils_dir is not None:
  +
  +    # opcode is not a virtualenv module, so we can use it to find the stdlib.
  +    # Technique taken from virtualenv's "distutils" package detection at
  +    # https://github.com/pypa/virtualenv/blob/16.3.0/virtualenv_embedded/distutils-init.py#L5
  +    import opcode
  +
  +    system_module_path = os.path.normpath(os.path.dirname(opcode.__file__))
  +    loaded_module_path = os.path.normpath(os.path.dirname(distutils.__file__))
  +    if system_module_path != loaded_module_path:
           # Find this package in its parent directory.
  -        api.search_dirs = [os.path.dirname(distutils_dir)]
  -        logger.info('distutils: retargeting to non-venv dir %r' % distutils_dir)
  +        api.search_dirs = [system_module_path]
  +        logger.info('distutils: retargeting to non-venv dir %r',
  +                    system_module_path)
  
verification_info: {"golden_diff": "diff --git a/PyInstaller/hooks/pre_find_module_path/hook-distutils.py b/PyInstaller/hooks/pre_find_module_path/hook-distutils.py\n--- a/PyInstaller/hooks/pre_find_module_path/hook-distutils.py\n+++ b/PyInstaller/hooks/pre_find_module_path/hook-distutils.py\n@@ -1,11 +1,11 @@\n-#-----------------------------------------------------------------------------\n+# -----------------------------------------------------------------------------\n # Copyright (c) 2005-2019, 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 \"\"\"\n `distutils`-specific pre-find module path hook.\n@@ -26,8 +26,16 @@\n def pre_find_module_path(api):\n     # Absolute path of the system-wide \"distutils\" package when run from within\n     # a venv or None otherwise.\n-    distutils_dir = getattr(distutils, 'distutils_path', None)\n-    if distutils_dir is not None:\n+\n+    # opcode is not a virtualenv module, so we can use it to find the stdlib.\n+    # Technique taken from virtualenv's \"distutils\" package detection at\n+    # https://github.com/pypa/virtualenv/blob/16.3.0/virtualenv_embedded/distutils-init.py#L5\n+    import opcode\n+\n+    system_module_path = os.path.normpath(os.path.dirname(opcode.__file__))\n+    loaded_module_path = os.path.normpath(os.path.dirname(distutils.__file__))\n+    if system_module_path != loaded_module_path:\n         # Find this package in its parent directory.\n-        api.search_dirs = [os.path.dirname(distutils_dir)]\n-        logger.info('distutils: retargeting to non-venv dir %r' % distutils_dir)\n+        api.search_dirs = [system_module_path]\n+        logger.info('distutils: retargeting to non-venv dir %r',\n+                    system_module_path)\n", "issue": "distutils not included with latest virtualenv (16.4.0)\nThis was already reported in #4031. The issue was closed without a fix so I'm creating this one.\r\n\r\n**With virtualenv 16.4.0, pyinstaller reports :**\r\n\r\n```\r\n3583 INFO: distutils: retargeting to non-venv dir '/usr/lib64/python3.6/distutils/__init__.py'\r\n```\r\nand then during \"Loading module hook\" sequence, the `hook-distutils.py` is missing and distutils modules are not included into the final executable binary.\r\n\r\nWhen executing the binary the error is:\r\n\r\n```\r\nModuleNotFoundError: No module named 'distutils'\r\n[10373] Failed to execute script <name here>\r\n```\r\n\r\n**With virtualenv 16.1.0, pyinstaller reports :**\r\n\r\n```\r\n3157 INFO: Processing pre-find module path hook   distutils\r\n5053 INFO: Loading module hook \"hook-distutils.py\"...\r\n```\r\n\r\nand distutils modules are included into the final executable binary.\r\n\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2005-2019, 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`distutils`-specific pre-find module path hook.\n\nWhen run from within a venv (virtual environment), this hook changes the\n`__path__` of the `distutils` package to that of the system-wide rather than\nvenv-specific `distutils` package. While the former is suitable for freezing,\nthe latter is intended for use _only_ from within venvs.\n\"\"\"\n\n\nimport distutils\nimport os\n\nfrom PyInstaller.utils.hooks import logger\n\n\ndef pre_find_module_path(api):\n    # Absolute path of the system-wide \"distutils\" package when run from within\n    # a venv or None otherwise.\n    distutils_dir = getattr(distutils, 'distutils_path', None)\n    if distutils_dir is not None:\n        # Find this package in its parent directory.\n        api.search_dirs = [os.path.dirname(distutils_dir)]\n        logger.info('distutils: retargeting to non-venv dir %r' % distutils_dir)\n", "path": "PyInstaller/hooks/pre_find_module_path/hook-distutils.py"}], "after_files": [{"content": "# -----------------------------------------------------------------------------\n# Copyright (c) 2005-2019, 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`distutils`-specific pre-find module path hook.\n\nWhen run from within a venv (virtual environment), this hook changes the\n`__path__` of the `distutils` package to that of the system-wide rather than\nvenv-specific `distutils` package. While the former is suitable for freezing,\nthe latter is intended for use _only_ from within venvs.\n\"\"\"\n\n\nimport distutils\nimport os\n\nfrom PyInstaller.utils.hooks import logger\n\n\ndef pre_find_module_path(api):\n    # Absolute path of the system-wide \"distutils\" package when run from within\n    # a venv or None otherwise.\n\n    # opcode is not a virtualenv module, so we can use it to find the stdlib.\n    # Technique taken from virtualenv's \"distutils\" package detection at\n    # https://github.com/pypa/virtualenv/blob/16.3.0/virtualenv_embedded/distutils-init.py#L5\n    import opcode\n\n    system_module_path = os.path.normpath(os.path.dirname(opcode.__file__))\n    loaded_module_path = os.path.normpath(os.path.dirname(distutils.__file__))\n    if system_module_path != loaded_module_path:\n        # Find this package in its parent directory.\n        api.search_dirs = [system_module_path]\n        logger.info('distutils: retargeting to non-venv dir %r',\n                    system_module_path)\n", "path": "PyInstaller/hooks/pre_find_module_path/hook-distutils.py"}]}