We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
with setuptools v70.0.0: `ModuleNotFoundError: No module named 'pkg_resources.extern'`
<!--
Welcome to the PyInstaller issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to PyInstaller
    - For questions and general support, use the discussions forum.
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
-->

<!-- +++ ONLY TEXT +++ DO NOT POST IMAGES +++ -->

## Description of the issue

I have added some TODO notes below but wanted to submit this sooner than later for any other users running into this issue today to be able to find it.

This morning I noticed an error in my tests that exercise PyInstaller generated Windows .exe's in CI.

https://github.com/Chia-Network/chia-blockchain/actions/runs/9175546125/job/25229722015?pr=16898
```
Traceback (most recent call last):
  File "Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py", line 158, in <module>
  File "Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py", line 36, in _pyi_rthook
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pkg_resources\__init__.py", line [7](https://github.com/Chia-Network/chia-blockchain/actions/runs/9175546125/job/25229722015?pr=16898#step:6:8)7, in <module>
ModuleNotFoundError: No module named 'pkg_resources.extern'
[2148] Failed to execute script 'pyi_rth_pkgres' due to unhandled exception!
```

First I correlated this with [the release of setuptools v70.0.0](https://pypi.org/project/setuptools/70.0.0/#history) a few hours earlier (and not a new PyInstaller release `:]`).  After looking here and finding no issues reported I checked over at setuptools and found https://github.com/pypa/setuptools/issues/4374.  In that discussion I noted that the issue appears with https://github.com/pypa/setuptools/commit/e9995828311c5e0c843622ca2be85e7f09f1ff0d and not its parent commit.  That commit does indeed change how some of the `pkg_resources.extern` imports are handled inside `pkg_resources`.  Another developer provided an example, though that example has not yet resulted in recreation of the issue.

### Context information (for bug reports)

* Output of `pyinstaller --version`: ```(paste here)``` (TODO: add this to my CI run)
* Version of Python: 3.10
* Platform: Windows (GitHub Actions runner)
* How you installed Python: in-house action https://github.com/chia-network/actions/setup-python that should, in this case, pass through to upstream https://github.com/actions/setup-python
* Did you also try this on another platform? Does it work there?

~Similar Linux (Rocky and Ubuntu) builds as well as macOS (Intel and ARM) builds and tests seem to continue to work fine.  I could afford to review these runs in more detail for other relevant changes, but have not quite yet.~

When forcing the setuptools to be installed, this does happen on all of the platforms we build executables for (Rocky, Ubuntu (Intel and ARM), macOS (Intel and ARM), Windows)

* try the latest development version, using the following command:

https://github.com/Chia-Network/chia-blockchain/actions/runs/9179289212/job/25241848658?pr=18051 shows the failure using `develop`, specifically 676584885f2dfa1f885ab6155a5eda9150892c03.

* follow *all* the instructions in our "If Things Go Wrong" Guide
  (https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong) and

### Make sure [everything is packaged correctly](https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs#make-sure-everything-is-packaged-correctly)

  * [x] start with clean installation
  * [ ] use the latest development version
  * [x] Run your frozen program **from a command window (shell)** — instead of double-clicking on it
  * [ ] Package your program in **--onedir mode**
  * [ ] Package **without UPX**, say: use the option `--noupx` or set `upx=False` in your .spec-file
  * [ ] Repackage you application in **verbose/debug mode**. For this, pass the option `--debug` to `pyi-makespec` or `pyinstaller` or use `EXE(..., debug=1, ...)` in your .spec file.


### A minimal example program which shows the error

TODO: I will try to create this

```
(paste text here)
“Minimal“ means: remove everything from your code which is not relevant for this bug,
esp. don't use external programs, remote requests, etc.
A very good example is https://gist.github.com/ronen/024cdae9ff2d50488438. This one helped
us reproducing and fixing a quite complex problem within approx 1 hour.
```

### Stacktrace / full error message


```
(paste text here)
```

Please also see <https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs>
for more about what would use to solve the issue.


--- 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-pkg_resources.py`
Content:
```
1 #-----------------------------------------------------------------------------
2 # Copyright (c) 2005-2023, 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 from PyInstaller.utils.hooks import collect_submodules, check_requirement, can_import_module
13 
14 # pkg_resources keeps vendored modules in its _vendor subpackage, and does sys.meta_path based import magic to expose
15 # them as pkg_resources.extern.*
16 
17 # The `railroad` package is an optional requirement for `pyparsing`. `pyparsing.diagrams` depends on `railroad`, so
18 # filter it out when `railroad` is not available.
19 if can_import_module('railroad'):
20     hiddenimports = collect_submodules('pkg_resources._vendor')
21 else:
22     hiddenimports = collect_submodules(
23         'pkg_resources._vendor', filter=lambda name: 'pkg_resources._vendor.pyparsing.diagram' not in name
24     )
25 
26 # pkg_resources v45.0 dropped support for Python 2 and added this module printing a warning. We could save some bytes if
27 # we would replace this by a fake module.
28 if check_requirement('setuptools >= 45.0.0, < 49.1.1'):
29     hiddenimports.append('pkg_resources.py2_warn')
30 
31 excludedimports = ['__main__']
32 
33 # Some more hidden imports. See:
34 # https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/15#issuecomment-663699288 `packaging` can either be
35 # its own package, or embedded in `pkg_resources._vendor.packaging`, or both.
36 hiddenimports += collect_submodules('packaging')
37 
38 # As of v60.7, setuptools vendored jaraco and has pkg_resources use it. Currently, the pkg_resources._vendor.jaraco
39 # namespace package cannot be automatically scanned due to limited support for pure namespace packages in our hook
40 # utilities.
41 #
42 # In setuptools 60.7.0, the vendored jaraco.text package included "Lorem Ipsum.txt" data file, which also has to be
43 # collected. However, the presence of the data file (and the resulting directory hierarchy) confuses the importer's
44 # redirection logic; instead of trying to work-around that, tell user to upgrade or downgrade their setuptools.
45 if check_requirement("setuptools == 60.7.0"):
46     raise SystemExit(
47         "ERROR: Setuptools 60.7.0 is incompatible with PyInstaller. "
48         "Downgrade to an earlier version or upgrade to a later version."
49     )
50 # In setuptools 60.7.1, the "Lorem Ipsum.txt" data file was dropped from the vendored jaraco.text package, so we can
51 # accommodate it with couple of hidden imports.
52 elif check_requirement("setuptools >= 60.7.1"):
53     hiddenimports += [
54         'pkg_resources._vendor.jaraco.functools',
55         'pkg_resources._vendor.jaraco.context',
56         'pkg_resources._vendor.jaraco.text',
57     ]
58
```
--- 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/hooks/hook-pkg_resources.py b/PyInstaller/hooks/hook-pkg_resources.py
--- a/PyInstaller/hooks/hook-pkg_resources.py
+++ b/PyInstaller/hooks/hook-pkg_resources.py
@@ -55,3 +55,9 @@
         'pkg_resources._vendor.jaraco.context',
         'pkg_resources._vendor.jaraco.text',
     ]
+
+# As of setuptools 70.0.0, we need pkg_resources.extern added to hidden imports.
+if check_requirement("setuptools >= 70.0.0"):
+    hiddenimports += [
+        'pkg_resources.extern',
+    ]

{"golden_diff": "diff --git a/PyInstaller/hooks/hook-pkg_resources.py b/PyInstaller/hooks/hook-pkg_resources.py\n--- a/PyInstaller/hooks/hook-pkg_resources.py\n+++ b/PyInstaller/hooks/hook-pkg_resources.py\n@@ -55,3 +55,9 @@\n         'pkg_resources._vendor.jaraco.context',\n         'pkg_resources._vendor.jaraco.text',\n     ]\n+\n+# As of setuptools 70.0.0, we need pkg_resources.extern added to hidden imports.\n+if check_requirement(\"setuptools >= 70.0.0\"):\n+    hiddenimports += [\n+        'pkg_resources.extern',\n+    ]\n", "issue": "with setuptools v70.0.0: `ModuleNotFoundError: No module named 'pkg_resources.extern'`\n<!--\r\nWelcome to the PyInstaller issue tracker! Before creating an issue, please heed the following:\r\n\r\n1. This tracker should only be used to report bugs and request features / enhancements to PyInstaller\r\n    - For questions and general support, use the discussions forum.\r\n2. Use the search function before creating a new issue. Duplicates will be closed and directed to\r\n   the original discussion.\r\n3. When making a bug report, make sure you provide all required information. The easier it is for\r\n   maintainers to reproduce, the faster it'll be fixed.\r\n-->\r\n\r\n<!-- +++ ONLY TEXT +++ DO NOT POST IMAGES +++ -->\r\n\r\n## Description of the issue\r\n\r\nI have added some TODO notes below but wanted to submit this sooner than later for any other users running into this issue today to be able to find it.\r\n\r\nThis morning I noticed an error in my tests that exercise PyInstaller generated Windows .exe's in CI.\r\n\r\nhttps://github.com/Chia-Network/chia-blockchain/actions/runs/9175546125/job/25229722015?pr=16898\r\n```\r\nTraceback (most recent call last):\r\n  File \"Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py\", line 158, in <module>\r\n  File \"Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py\", line 36, in _pyi_rthook\r\n  File \"PyInstaller\\loader\\pyimod02_importers.py\", line 419, in exec_module\r\n  File \"pkg_resources\\__init__.py\", line [7](https://github.com/Chia-Network/chia-blockchain/actions/runs/9175546125/job/25229722015?pr=16898#step:6:8)7, in <module>\r\nModuleNotFoundError: No module named 'pkg_resources.extern'\r\n[2148] Failed to execute script 'pyi_rth_pkgres' due to unhandled exception!\r\n```\r\n\r\nFirst I correlated this with [the release of setuptools v70.0.0](https://pypi.org/project/setuptools/70.0.0/#history) a few hours earlier (and not a new PyInstaller release `:]`).  After looking here and finding no issues reported I checked over at setuptools and found https://github.com/pypa/setuptools/issues/4374.  In that discussion I noted that the issue appears with https://github.com/pypa/setuptools/commit/e9995828311c5e0c843622ca2be85e7f09f1ff0d and not its parent commit.  That commit does indeed change how some of the `pkg_resources.extern` imports are handled inside `pkg_resources`.  Another developer provided an example, though that example has not yet resulted in recreation of the issue.\r\n\r\n### Context information (for bug reports)\r\n\r\n* Output of `pyinstaller --version`: ```(paste here)``` (TODO: add this to my CI run)\r\n* Version of Python: 3.10\r\n* Platform: Windows (GitHub Actions runner)\r\n* How you installed Python: in-house action https://github.com/chia-network/actions/setup-python that should, in this case, pass through to upstream https://github.com/actions/setup-python\r\n* Did you also try this on another platform? Does it work there?\r\n\r\n~Similar Linux (Rocky and Ubuntu) builds as well as macOS (Intel and ARM) builds and tests seem to continue to work fine.  I could afford to review these runs in more detail for other relevant changes, but have not quite yet.~\r\n\r\nWhen forcing the setuptools to be installed, this does happen on all of the platforms we build executables for (Rocky, Ubuntu (Intel and ARM), macOS (Intel and ARM), Windows)\r\n\r\n* try the latest development version, using the following command:\r\n\r\nhttps://github.com/Chia-Network/chia-blockchain/actions/runs/9179289212/job/25241848658?pr=18051 shows the failure using `develop`, specifically 676584885f2dfa1f885ab6155a5eda9150892c03.\r\n\r\n* follow *all* the instructions in our \"If Things Go Wrong\" Guide\r\n  (https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong) and\r\n\r\n### Make sure [everything is packaged correctly](https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs#make-sure-everything-is-packaged-correctly)\r\n\r\n  * [x] start with clean installation\r\n  * [ ] use the latest development version\r\n  * [x] Run your frozen program **from a command window (shell)** \u2014 instead of double-clicking on it\r\n  * [ ] Package your program in **--onedir mode**\r\n  * [ ] Package **without UPX**, say: use the option `--noupx` or set `upx=False` in your .spec-file\r\n  * [ ] Repackage you application in **verbose/debug mode**. For this, pass the option `--debug` to `pyi-makespec` or `pyinstaller` or use `EXE(..., debug=1, ...)` in your .spec file.\r\n\r\n\r\n### A minimal example program which shows the error\r\n\r\nTODO: I will try to create this\r\n\r\n```\r\n(paste text here)\r\n\u201cMinimal\u201c means: remove everything from your code which is not relevant for this bug,\r\nesp. don't use external programs, remote requests, etc.\r\nA very good example is https://gist.github.com/ronen/024cdae9ff2d50488438. This one helped\r\nus reproducing and fixing a quite complex problem within approx 1 hour.\r\n```\r\n\r\n### Stacktrace / full error message\r\n\r\n\r\n```\r\n(paste text here)\r\n```\r\n\r\nPlease also see <https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs>\r\nfor more about what would use to solve the issue.\r\n\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2005-2023, 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\nfrom PyInstaller.utils.hooks import collect_submodules, check_requirement, can_import_module\n\n# pkg_resources keeps vendored modules in its _vendor subpackage, and does sys.meta_path based import magic to expose\n# them as pkg_resources.extern.*\n\n# The `railroad` package is an optional requirement for `pyparsing`. `pyparsing.diagrams` depends on `railroad`, so\n# filter it out when `railroad` is not available.\nif can_import_module('railroad'):\n    hiddenimports = collect_submodules('pkg_resources._vendor')\nelse:\n    hiddenimports = collect_submodules(\n        'pkg_resources._vendor', filter=lambda name: 'pkg_resources._vendor.pyparsing.diagram' not in name\n    )\n\n# pkg_resources v45.0 dropped support for Python 2 and added this module printing a warning. We could save some bytes if\n# we would replace this by a fake module.\nif check_requirement('setuptools >= 45.0.0, < 49.1.1'):\n    hiddenimports.append('pkg_resources.py2_warn')\n\nexcludedimports = ['__main__']\n\n# Some more hidden imports. See:\n# https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/15#issuecomment-663699288 `packaging` can either be\n# its own package, or embedded in `pkg_resources._vendor.packaging`, or both.\nhiddenimports += collect_submodules('packaging')\n\n# As of v60.7, setuptools vendored jaraco and has pkg_resources use it. Currently, the pkg_resources._vendor.jaraco\n# namespace package cannot be automatically scanned due to limited support for pure namespace packages in our hook\n# utilities.\n#\n# In setuptools 60.7.0, the vendored jaraco.text package included \"Lorem Ipsum.txt\" data file, which also has to be\n# collected. However, the presence of the data file (and the resulting directory hierarchy) confuses the importer's\n# redirection logic; instead of trying to work-around that, tell user to upgrade or downgrade their setuptools.\nif check_requirement(\"setuptools == 60.7.0\"):\n    raise SystemExit(\n        \"ERROR: Setuptools 60.7.0 is incompatible with PyInstaller. \"\n        \"Downgrade to an earlier version or upgrade to a later version.\"\n    )\n# In setuptools 60.7.1, the \"Lorem Ipsum.txt\" data file was dropped from the vendored jaraco.text package, so we can\n# accommodate it with couple of hidden imports.\nelif check_requirement(\"setuptools >= 60.7.1\"):\n    hiddenimports += [\n        'pkg_resources._vendor.jaraco.functools',\n        'pkg_resources._vendor.jaraco.context',\n        'pkg_resources._vendor.jaraco.text',\n    ]\n", "path": "PyInstaller/hooks/hook-pkg_resources.py"}], "after_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2005-2023, 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\nfrom PyInstaller.utils.hooks import collect_submodules, check_requirement, can_import_module\n\n# pkg_resources keeps vendored modules in its _vendor subpackage, and does sys.meta_path based import magic to expose\n# them as pkg_resources.extern.*\n\n# The `railroad` package is an optional requirement for `pyparsing`. `pyparsing.diagrams` depends on `railroad`, so\n# filter it out when `railroad` is not available.\nif can_import_module('railroad'):\n    hiddenimports = collect_submodules('pkg_resources._vendor')\nelse:\n    hiddenimports = collect_submodules(\n        'pkg_resources._vendor', filter=lambda name: 'pkg_resources._vendor.pyparsing.diagram' not in name\n    )\n\n# pkg_resources v45.0 dropped support for Python 2 and added this module printing a warning. We could save some bytes if\n# we would replace this by a fake module.\nif check_requirement('setuptools >= 45.0.0, < 49.1.1'):\n    hiddenimports.append('pkg_resources.py2_warn')\n\nexcludedimports = ['__main__']\n\n# Some more hidden imports. See:\n# https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/15#issuecomment-663699288 `packaging` can either be\n# its own package, or embedded in `pkg_resources._vendor.packaging`, or both.\nhiddenimports += collect_submodules('packaging')\n\n# As of v60.7, setuptools vendored jaraco and has pkg_resources use it. Currently, the pkg_resources._vendor.jaraco\n# namespace package cannot be automatically scanned due to limited support for pure namespace packages in our hook\n# utilities.\n#\n# In setuptools 60.7.0, the vendored jaraco.text package included \"Lorem Ipsum.txt\" data file, which also has to be\n# collected. However, the presence of the data file (and the resulting directory hierarchy) confuses the importer's\n# redirection logic; instead of trying to work-around that, tell user to upgrade or downgrade their setuptools.\nif check_requirement(\"setuptools == 60.7.0\"):\n    raise SystemExit(\n        \"ERROR: Setuptools 60.7.0 is incompatible with PyInstaller. \"\n        \"Downgrade to an earlier version or upgrade to a later version.\"\n    )\n# In setuptools 60.7.1, the \"Lorem Ipsum.txt\" data file was dropped from the vendored jaraco.text package, so we can\n# accommodate it with couple of hidden imports.\nelif check_requirement(\"setuptools >= 60.7.1\"):\n    hiddenimports += [\n        'pkg_resources._vendor.jaraco.functools',\n        'pkg_resources._vendor.jaraco.context',\n        'pkg_resources._vendor.jaraco.text',\n    ]\n\n# As of setuptools 70.0.0, we need pkg_resources.extern added to hidden imports.\nif check_requirement(\"setuptools >= 70.0.0\"):\n    hiddenimports += [\n        'pkg_resources.extern',\n    ]\n", "path": "PyInstaller/hooks/hook-pkg_resources.py"}]}