I need to install a Python package in a custom Docker container that I'm building from the official 'ubuntu' Docker image, so I want to minimize how much space this uses. Python3 installs fine and runs, but for some reason, pip is not included.
So I installed via apt install python3-pip, this works but it is a whopping 300 megs and takes a couple of minutes to install (apparently because it installs a sh*load of stuff to build binary packages from gcc etc).
Of course I could uninstall python3-pip from the image after installing the dependencies I want, and additionally use apt autoremove to get rid of 299 megs. However this takes another minute.
So although the above works, it significantly increases the build time of my Docker image. So I tried to see if there was a way of installing the dependency without pip:
I tried downloading the dependency's .tar.gz from PyPI, extracted, and tried python3 setup.py install, but this gets me an odd error:
Traceback (most recent call last):
File "setup.py", line 59, in <module>
from distutils import log
ImportError: cannot import name 'log'
I thought perhaps I need to install setuptools, or upgrade distutils.
I tried to use get-pip.py from the official site but that failed too:
Traceback (most recent call last):
File "get-pip.py", line 20890, in <module>
main()
File "get-pip.py", line 197, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip._internal
File "/tmp/tmpjpa5gs_x/pip.zip/pip/_internal/__init__.py", line 40, in <module>
File "/tmp/tmpjpa5gs_x/pip.zip/pip/_internal/cli/autocompletion.py", line 8, in <module>
File "/tmp/tmpjpa5gs_x/pip.zip/pip/_internal/cli/main_parser.py", line 8, in <module>
File "/tmp/tmpjpa5gs_x/pip.zip/pip/_internal/cli/cmdoptions.py", line 17, in <module>
File "/tmp/tmpjpa5gs_x/pip.zip/pip/_internal/locations.py", line 10, in <module>
ImportError: cannot import name 'sysconfig'
which is very weird because if I start python3, import sysconfig works fine.
I also tried apt install python-pyyaml (the dependency I need in my Docker image) but that doesn't seem to exist.
So I'm out of options.
pipactually really needs all this (the C compiler and other build tools) because pip packages might contain C code or link with binary packages.