使用Wagtail 1.13.1本地Docker构建失败:urllib3卸载报错求助
Hey Joss, let's tackle your questions one by one:
Is urllib3 a dependency introduced by Wagtail via Requests?
Yes, exactly. For Wagtail 1.13.1, one of its core dependencies is requests>=2.11.1 (you can verify this in the official Wagtail requirements for that version). And Requests relies heavily on urllib3 as a foundational dependency—so urllib3 does come into your project indirectly through Wagtail → Requests.
That said, the root of your Docker build error is likely that your base Python image (like the official python: images) pre-installs urllib3 using distutils, not pip. Pip struggles to uninstall distutils-installed packages because it can't track all their associated files accurately.
Have other users encountered this Docker build failure issue?
Absolutely, this is a common pain point for many developers working with Docker and Python projects. The error pops up whenever pip tries to update a system-level package that was installed via distutils instead of pip. You'll find countless threads from folks hitting the same "Cannot uninstall 'urllib3'. It is a distutils installed project..." message in their build logs.
Quick Fixes to Try
Here are a few reliable solutions that work for most cases:
- Add the
--ignore-installed urllib3flag to your pip install command: This tells pip to skip uninstalling the existing distutils-installed urllib3 and just install the version your project needs alongside it. Update your Dockerfile's install step to something like:RUN pip install --ignore-installed urllib3 -r requirements.txt - Pin urllib3 to the version pre-installed in your base image: Check what urllib3 version comes with your Python image (run
pip show urllib3in a temporary container of that image), then addurllib3==X.Y.Zto your requirements.txt to match it. This avoids pip trying to update the package entirely. - Use a different base image or install urllib3 via apt: For Debian/Ubuntu-based images, you can install urllib3 through the system package manager first (
apt-get install python3-urllib3) before running pip install. This replaces the distutils version with a pip-manageable one.
内容的提问来源于stack exchange,提问作者joss

