damnever / pigar

:coffee: A tool to generate requirements.txt for Python project, and more than that. (IT IS NOT A PACKAGE MANAGEMENT TOOL)
https://damnever.github.io/pigar/
BSD 3-Clause "New" or "Revised" License
1.61k stars 90 forks source link

Cannot run with pip 24.x; chardet is no longer vendored with pip #212

Closed tpanza closed 2 weeks ago

tpanza commented 2 weeks ago

Describe the bug A fresh install with Python 3.11.9 and pip 24.1.2 causes pigar to fail when invoked from command-line: ModuleNotFoundError: No module named 'pip._vendor.chardet'

To Reproduce Steps to reproduce the behavior:

  1. Install and activate a fresh conda environment with Python 3.11.9
  2. Upgrade pip to latest, 24.1.2: python -m pip install -U pip
  3. Install pigar: python -m pip install pigar
  4. Run pigar generate
  5. See error..
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Scripts\pigar.exe\__main__.py", line 4, in <module>
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\__main__.py", line 12, in <module>
    from .log import enable_pretty_logging, logger
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\log.py", line 3, in <module>
    from .helpers import Color
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\helpers.py", line 13, in <module>
    from ._vendor.pip._internal.req.req_file import get_file_content
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\_vendor\pip\_internal\req\__init__.py", line 5, in <module>
    from pigar._vendor.pip._internal.utils.logging import indent_log
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\_vendor\pip\_internal\utils\logging.py", line 29, in <module>
    from pigar._vendor.pip._internal.utils.misc import ensure_dir
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\_vendor\pip\_internal\utils\misc.py", line 43, in <module>
    from pigar._vendor.pip._internal.exceptions import CommandError, ExternallyManagedEnvironment
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\_vendor\pip\_internal\exceptions.py", line 18, in <module>
    from pigar._vendor.pip._vendor.requests.models import Request, Response
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\_vendor\pip\_vendor\requests\__init__.py", line 149, in <module>
    from . import packages, utils
  File "C:\Users\myusername\work\mambaforge\envs\py311env\Lib\site-packages\pigar\_vendor\pip\_vendor\requests\packages.py", line 8, in <module>
    locals()[package] = __import__(vendored_package)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pip._vendor.chardet'

Expected behavior The command should run successfully and not raise ModuleNotFoundError

Context (Environment)

Additional context

Forcing a downgrade of pip to 20.3 made the error go away. Obviously not a long term solution.

As best I can tell, this error is due to pip dropping its vendoring of the chardet library sometime between versions 20.3 and 24.1.

See here: https://github.com/pypa/pip/tree/main/src/pip/_vendor : chardet is no longer vendored.

tpanza commented 2 weeks ago

The discussion in pypa/pip#12703 might be relevant

damnever commented 2 weeks ago

This issue is the same as https://github.com/damnever/pigar/issues/207, will release a fix soon.

damnever commented 2 weeks ago

Try the latest release: pip install pigar==2.1.6.