Fix ImportError by replacing distlib.compat.raw_input with built-in input() #241
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When installing
django-tailwindwithout optional dependencies, users encounter anImportError:ModuleNotFoundError: No module named 'distlib'
This occurs because:
distlibis not listed as a required dependency inpyproject.toml(onlydjangoandpytailwindcssare)distlibis only available as a transitive dependency through the optionalcookiecutterpackage(
cookiecutter→virtualenv→distlib)from distlib.compat import raw_inputat the module levelI encountered this issue when building a Docker image with
pip install django-tailwind, whichdoesn't include optional dependencies.
Solution
Since
django-tailwindrequires Python 3.11+ (as specified inpyproject.toml), we can safely usePython 3's built-in
input()function instead of the Python 2/3 compatibility wrapper.Changes made:
from distlib.compat import raw_inputimportraw_input()withinput()In Python 3,
input()behaves identically to Python 2'sraw_input()(returns a string withoutevaluation).
Testing
uv run pytest)This fix ensures users can install and use
django-tailwindwith only the required dependencieslisted in
pyproject.toml.