Repository: pypa/pip

Issue:
3.12 support
### Description

While trying to add 3.12 support to virtualenv noticed that pip depends on distutils:


```
 'Remainder of file ignored\n'
 'Traceback (most recent call last):\n'
 '  File "/tmp/pytest-of-runner/pytest-0/test_app_data_pinning0/bin/pip", line '
 '5, in <module>\n'
 '    from pip._internal.main import main\n'
 '  File '
 '"/tmp/pytest-of-runner/pytest-0/test_app_data_pinning0/lib/python3.12/site-packages/pip/_internal/main.py", '
 'line 13, in <module>\n'
 '    from pip._internal.cli.autocompletion import autocomplete\n'
 '  File '
 '"/tmp/pytest-of-runner/pytest-0/test_app_data_pinning0/lib/python3.12/site-packages/pip/_internal/cli/autocompletion.py", '
 'line 11, in <module>\n'
 '    from pip._internal.cli.main_parser import create_main_parser\n'
 '  File '
 '"/tmp/pytest-of-runner/pytest-0/test_app_data_pinning0/lib/python3.12/site-packages/pip/_internal/cli/main_parser.py", '
 'line 7, in <module>\n'
 '    from pip._internal.cli import cmdoptions\n'
 '  File '
 '"/tmp/pytest-of-runner/pytest-0/test_app_data_pinning0/lib/python3.12/site-packages/pip/_internal/cli/cmdoptions.py", '
 'line 19, in <module>\n'
 '    from distutils.util import strtobool\n'
```

### pip version

latest

### Python version

3.12

### OS

any

### How to Reproduce

Run pip on 3.12 no setuptools.

### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
As of last night's 3.12 build, I get this error:
```
% .tox/anypy/bin/python -m pip install rich
ERROR: Exception:
Traceback (most recent call last):
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 160, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 326, in run
    session = self.get_default_session(options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 98, in get_default_session
    self._session = self.enter_context(self._build_session(options))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 125, in _build_session
    session = PipSession(
              ^^^^^^^^^^^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/network/session.py", line 343, in __init__
    self.headers["User-Agent"] = user_agent()
                                 ^^^^^^^^^^^^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/network/session.py", line 175, in user_agent
    setuptools_dist = get_default_environment().get_distribution("setuptools")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 188, in get_distribution
    return next(matches, None)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 183, in <genexpr>
    matches = (
              ^
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/metadata/base.py", line 612, in iter_all_distributions
    for dist in self._iter_distributions():
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 176, in _iter_distributions
    for dist in finder.find_eggs(location):
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 144, in find_eggs
    yield from self._find_eggs_in_dir(location)
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 111, in _find_eggs_in_dir
    from pip._vendor.pkg_resources import find_distributions
  File "/Users/nedbatchelder/coverage/trunk/.tox/anypy/lib/python3.12/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
```
Is this with the latest release (23.1.2)? That's the release that added support for the new 3.12 build, anything older than that won't work with 3.12.
@gaborbernat The same comment is true for the original issue - `strtobool` is no longer imported from `distutils` in 3.12.
Hmm, it looks like although i have pip pinned to 23.1.2, in my tox environment, I have 22.3.1.  My bad, I have to untangle this.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -42,6 +42,7 @@ def get_version(rel_path: str) -> str:
         "Programming Language :: Python :: 3.9",
         "Programming Language :: Python :: 3.10",
         "Programming Language :: Python :: 3.11",
+        "Programming Language :: Python :: 3.12",
         "Programming Language :: Python :: Implementation :: CPython",
         "Programming Language :: Python :: Implementation :: PyPy",
     ],


Test patch: