prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  OS X ImportError: _sysconfigdata_m_darwin_ not found
  # Description
  When running a standalone executable that was built with PyInstaller on OS X, I receive the following error:
  ```
  [7943] LOADER: Running pyiboot01_bootstrap.py
  [7943] LOADER: Running pyi_rth_multiprocessing.py
  [7943] LOADER: Running pyi_rth_pkgres.py
  Traceback (most recent call last):
    File "site-packages/PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 11, in <module>
    File "/Users/addisonelliott/anaconda3/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
      exec(bytecode, module.__dict__)
    File "site-packages/pkg_resources/__init__.py", line 995, in <module>
    File "site-packages/pkg_resources/__init__.py", line 998, in Environment
    File "site-packages/pkg_resources/__init__.py", line 284, in get_supported_platform
    File "site-packages/pkg_resources/__init__.py", line 480, in get_build_platform
    File "sysconfig.py", line 688, in get_platform
    File "sysconfig.py", line 549, in get_config_vars
    File "sysconfig.py", line 420, in _init_posix
  ImportError: No module named '_sysconfigdata_m_darwin_'
  ```
  Issue is specific to OS X. I tested on Windows as well as Ubuntu (using WSL) and the issue was not present on either OS. Note that I can build the executable but the error occurs on **run-time**.
  
  # Build Setup
  * OS: Mac OS X 10.11 El Capitan
  * Platform: Darwin-15.6.0-x86_64-i386-64bit
  * Python: 3.5.4 using Anaconda
  * PyInstaller: Tested with develop(3.4), 3.2.1, and 3.3 and issue occurs on all
  
  # Example Setup
  I have found that importing numpy in my case will trigger the error. If you comment out the import, it works fine. Create a Python script, paste the following code and then create an executable from it.
  ```
  import numpy
  
  print('Hello world')
  ```
  
  And here is the command I am using to compile the code: 
  ```
  sudo pyinstaller -y --debug --clean --onedir main.py
  ```
  
  # What I have discovered
  I have discovered that using the hidden-import argument, this fixes the issue. The goal is to create/edit a hook and apply this fix in a more permanent method however.
  
  The failed import module occurs in CPython: https://github.com/python/cpython/blob/master/Lib/sysconfig.py#L339
  
  In Linux, the imported module is _sysconfigdata which is odd because that doesn't match the Github. I looked at sysconfig.py in Linux and it had some outdated code that just imported _sysconfigdata module and did not look at ABI, OS, etc.
  
  Some type of alteration will need to be done to the sysconfig hook most likely: https://github.com/pyinstaller/pyinstaller/blob/develop/PyInstaller/hooks/hook-sysconfig.py
  
  I am going to attempt to create a PR for this. Currently, my questions are:
  * What does the sysconfig hook load now?
  * Did something change in Python that caused the _sysconfigdata module to be different?
  * If so, what version did this occur?
  
  **Edit:**
  Here is some of the information I have discovered. For reasons I don't know, the CPython GitHub does not match up with the Python implementation from Anaconda. For example, Python 3.5.4 in Anaconda backports the sysconfig changes in 3.6. This does not match up with CPython on Github because the sysconfig changes are not present until 3.6.
  
  This is ultimately what is causing the issue. The sysconfig hook for PyInstaller assumes that only Python versions 3.6 and up will contain the _get_sysconfigdata_name() function. Since this also occurs in 3.5.4 for Anaconda, there is an issue.
  
  Below is the sysconfig.py file for my Anaconda 3.5.4 environment:
  ```
  def _init_posix(vars):
      """Initialize the module as appropriate for POSIX systems."""
      # _sysconfigdata is generated at build time, see _generate_posix_vars()
      # _PYTHON_SYSCONFIGDATA_NAME support backported from Python 3.6
      name = _get_sysconfigdata_name()
      _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
      build_time_vars = _temp.build_time_vars
      vars.update(build_time_vars)
  ```
  
  --- 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/hook-sysconfig.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 # The 'sysconfig' module requires Makefile and pyconfig.h files from
  12 # Python installation. 'sysconfig' parses these files to get some
  13 # information from them.
  14 # TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3.
  15 
  16 import sysconfig
  17 import os
  18 
  19 from PyInstaller.utils.hooks import relpath_to_config_or_make
  20 from PyInstaller.compat import is_py36, is_win
  21 
  22 _CONFIG_H = sysconfig.get_config_h_filename()
  23 if hasattr(sysconfig, 'get_makefile_filename'):
  24     # sysconfig.get_makefile_filename is missing in Python < 2.7.9
  25     _MAKEFILE = sysconfig.get_makefile_filename()
  26 else:
  27     _MAKEFILE = sysconfig._get_makefile_filename()
  28 
  29 
  30 datas = [(_CONFIG_H, relpath_to_config_or_make(_CONFIG_H))]
  31 
  32 # The Makefile does not exist on all platforms, eg. on Windows
  33 if os.path.exists(_MAKEFILE):
  34     datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE)))
  35 
  36 if is_py36 and not is_win:
  37     # Python 3.6 uses additional modules like
  38     # `_sysconfigdata_m_linux_x86_64-linux-gnu`, see
  39     # https://github.com/python/cpython/blob/3.6/Lib/sysconfig.py#L417
  40     hiddenimports = [sysconfig._get_sysconfigdata_name()]
  41
  ```
  --- 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/hook-sysconfig.py b/PyInstaller/hooks/hook-sysconfig.py
  --- a/PyInstaller/hooks/hook-sysconfig.py
  +++ b/PyInstaller/hooks/hook-sysconfig.py
  @@ -17,7 +17,7 @@
   import os
   
   from PyInstaller.utils.hooks import relpath_to_config_or_make
  -from PyInstaller.compat import is_py36, is_win
  +from PyInstaller.compat import is_win
   
   _CONFIG_H = sysconfig.get_config_h_filename()
   if hasattr(sysconfig, 'get_makefile_filename'):
  @@ -33,8 +33,10 @@
   if os.path.exists(_MAKEFILE):
       datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE)))
   
  -if is_py36 and not is_win:
  +if not is_win and hasattr(sysconfig, '_get_sysconfigdata_name'):
       # Python 3.6 uses additional modules like
       # `_sysconfigdata_m_linux_x86_64-linux-gnu`, see
       # https://github.com/python/cpython/blob/3.6/Lib/sysconfig.py#L417
  +    # Note: Some versions of Anaconda backport this feature to before 3.6.
  +    # See issue #3105
       hiddenimports = [sysconfig._get_sysconfigdata_name()]
  
verification_info: {"golden_diff": "diff --git a/PyInstaller/hooks/hook-sysconfig.py b/PyInstaller/hooks/hook-sysconfig.py\n--- a/PyInstaller/hooks/hook-sysconfig.py\n+++ b/PyInstaller/hooks/hook-sysconfig.py\n@@ -17,7 +17,7 @@\n import os\n \n from PyInstaller.utils.hooks import relpath_to_config_or_make\n-from PyInstaller.compat import is_py36, is_win\n+from PyInstaller.compat import is_win\n \n _CONFIG_H = sysconfig.get_config_h_filename()\n if hasattr(sysconfig, 'get_makefile_filename'):\n@@ -33,8 +33,10 @@\n if os.path.exists(_MAKEFILE):\n     datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE)))\n \n-if is_py36 and not is_win:\n+if not is_win and hasattr(sysconfig, '_get_sysconfigdata_name'):\n     # Python 3.6 uses additional modules like\n     # `_sysconfigdata_m_linux_x86_64-linux-gnu`, see\n     # https://github.com/python/cpython/blob/3.6/Lib/sysconfig.py#L417\n+    # Note: Some versions of Anaconda backport this feature to before 3.6.\n+    # See issue #3105\n     hiddenimports = [sysconfig._get_sysconfigdata_name()]\n", "issue": "OS X ImportError: _sysconfigdata_m_darwin_ not found\n# Description\r\nWhen running a standalone executable that was built with PyInstaller on OS X, I receive the following error:\r\n```\r\n[7943] LOADER: Running pyiboot01_bootstrap.py\r\n[7943] LOADER: Running pyi_rth_multiprocessing.py\r\n[7943] LOADER: Running pyi_rth_pkgres.py\r\nTraceback (most recent call last):\r\n  File \"site-packages/PyInstaller/loader/rthooks/pyi_rth_pkgres.py\", line 11, in <module>\r\n  File \"/Users/addisonelliott/anaconda3/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py\", line 631, in exec_module\r\n    exec(bytecode, module.__dict__)\r\n  File \"site-packages/pkg_resources/__init__.py\", line 995, in <module>\r\n  File \"site-packages/pkg_resources/__init__.py\", line 998, in Environment\r\n  File \"site-packages/pkg_resources/__init__.py\", line 284, in get_supported_platform\r\n  File \"site-packages/pkg_resources/__init__.py\", line 480, in get_build_platform\r\n  File \"sysconfig.py\", line 688, in get_platform\r\n  File \"sysconfig.py\", line 549, in get_config_vars\r\n  File \"sysconfig.py\", line 420, in _init_posix\r\nImportError: No module named '_sysconfigdata_m_darwin_'\r\n```\r\nIssue is specific to OS X. I tested on Windows as well as Ubuntu (using WSL) and the issue was not present on either OS. Note that I can build the executable but the error occurs on **run-time**.\r\n\r\n# Build Setup\r\n* OS: Mac OS X 10.11 El Capitan\r\n* Platform: Darwin-15.6.0-x86_64-i386-64bit\r\n* Python: 3.5.4 using Anaconda\r\n* PyInstaller: Tested with develop(3.4), 3.2.1, and 3.3 and issue occurs on all\r\n\r\n# Example Setup\r\nI have found that importing numpy in my case will trigger the error. If you comment out the import, it works fine. Create a Python script, paste the following code and then create an executable from it.\r\n```\r\nimport numpy\r\n\r\nprint('Hello world')\r\n```\r\n\r\nAnd here is the command I am using to compile the code: \r\n```\r\nsudo pyinstaller -y --debug --clean --onedir main.py\r\n```\r\n\r\n# What I have discovered\r\nI have discovered that using the hidden-import argument, this fixes the issue. The goal is to create/edit a hook and apply this fix in a more permanent method however.\r\n\r\nThe failed import module occurs in CPython: https://github.com/python/cpython/blob/master/Lib/sysconfig.py#L339\r\n\r\nIn Linux, the imported module is _sysconfigdata which is odd because that doesn't match the Github. I looked at sysconfig.py in Linux and it had some outdated code that just imported _sysconfigdata module and did not look at ABI, OS, etc.\r\n\r\nSome type of alteration will need to be done to the sysconfig hook most likely: https://github.com/pyinstaller/pyinstaller/blob/develop/PyInstaller/hooks/hook-sysconfig.py\r\n\r\nI am going to attempt to create a PR for this. Currently, my questions are:\r\n* What does the sysconfig hook load now?\r\n* Did something change in Python that caused the _sysconfigdata module to be different?\r\n* If so, what version did this occur?\r\n\r\n**Edit:**\r\nHere is some of the information I have discovered. For reasons I don't know, the CPython GitHub does not match up with the Python implementation from Anaconda. For example, Python 3.5.4 in Anaconda backports the sysconfig changes in 3.6. This does not match up with CPython on Github because the sysconfig changes are not present until 3.6.\r\n\r\nThis is ultimately what is causing the issue. The sysconfig hook for PyInstaller assumes that only Python versions 3.6 and up will contain the _get_sysconfigdata_name() function. Since this also occurs in 3.5.4 for Anaconda, there is an issue.\r\n\r\nBelow is the sysconfig.py file for my Anaconda 3.5.4 environment:\r\n```\r\ndef _init_posix(vars):\r\n    \"\"\"Initialize the module as appropriate for POSIX systems.\"\"\"\r\n    # _sysconfigdata is generated at build time, see _generate_posix_vars()\r\n    # _PYTHON_SYSCONFIGDATA_NAME support backported from Python 3.6\r\n    name = _get_sysconfigdata_name()\r\n    _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)\r\n    build_time_vars = _temp.build_time_vars\r\n    vars.update(build_time_vars)\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# The 'sysconfig' module requires Makefile and pyconfig.h files from\n# Python installation. 'sysconfig' parses these files to get some\n# information from them.\n# TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3.\n\nimport sysconfig\nimport os\n\nfrom PyInstaller.utils.hooks import relpath_to_config_or_make\nfrom PyInstaller.compat import is_py36, is_win\n\n_CONFIG_H = sysconfig.get_config_h_filename()\nif hasattr(sysconfig, 'get_makefile_filename'):\n    # sysconfig.get_makefile_filename is missing in Python < 2.7.9\n    _MAKEFILE = sysconfig.get_makefile_filename()\nelse:\n    _MAKEFILE = sysconfig._get_makefile_filename()\n\n\ndatas = [(_CONFIG_H, relpath_to_config_or_make(_CONFIG_H))]\n\n# The Makefile does not exist on all platforms, eg. on Windows\nif os.path.exists(_MAKEFILE):\n    datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE)))\n\nif is_py36 and not is_win:\n    # Python 3.6 uses additional modules like\n    # `_sysconfigdata_m_linux_x86_64-linux-gnu`, see\n    # https://github.com/python/cpython/blob/3.6/Lib/sysconfig.py#L417\n    hiddenimports = [sysconfig._get_sysconfigdata_name()]\n", "path": "PyInstaller/hooks/hook-sysconfig.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# The 'sysconfig' module requires Makefile and pyconfig.h files from\n# Python installation. 'sysconfig' parses these files to get some\n# information from them.\n# TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3.\n\nimport sysconfig\nimport os\n\nfrom PyInstaller.utils.hooks import relpath_to_config_or_make\nfrom PyInstaller.compat import is_win\n\n_CONFIG_H = sysconfig.get_config_h_filename()\nif hasattr(sysconfig, 'get_makefile_filename'):\n    # sysconfig.get_makefile_filename is missing in Python < 2.7.9\n    _MAKEFILE = sysconfig.get_makefile_filename()\nelse:\n    _MAKEFILE = sysconfig._get_makefile_filename()\n\n\ndatas = [(_CONFIG_H, relpath_to_config_or_make(_CONFIG_H))]\n\n# The Makefile does not exist on all platforms, eg. on Windows\nif os.path.exists(_MAKEFILE):\n    datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE)))\n\nif not is_win and hasattr(sysconfig, '_get_sysconfigdata_name'):\n    # Python 3.6 uses additional modules like\n    # `_sysconfigdata_m_linux_x86_64-linux-gnu`, see\n    # https://github.com/python/cpython/blob/3.6/Lib/sysconfig.py#L417\n    # Note: Some versions of Anaconda backport this feature to before 3.6.\n    # See issue #3105\n    hiddenimports = [sysconfig._get_sysconfigdata_name()]\n", "path": "PyInstaller/hooks/hook-sysconfig.py"}]}