python install without pip on ubuntu
I ran into a similar issue and wanted to give an alternative solution.
On Ubuntu 20.04 build-essential and python3-dev are recommended packages for python3-pip, therefore you can use the --no-install-recommends
option to skip them:
RUN apt update -y && \
apt install python3 python3-pip --no-install-recommends -y && \
apt clean
This took my image from 420MB to 165MB, and obviously the build time was also quicker.
Note: this will work fine for pure-Python packages, but you will likely need build-essential and python3-dev if you want to compile anything
Useful links
- https://packages.ubuntu.com/focal/python3-pip
- https://manpages.ubuntu.com/manpages/xenial/man8/apt-get.8.html
The Debian and Ubuntu package for PyYAML is called python-yaml
, not python-pyyaml
.
sudo apt install python-yaml
or
sudo apt install python3-yaml
respectively.
(It seems to be common in Debian/Ubuntu package names to drop any additional "py" prefix that a Python package might have: it's apt install python-tz
instead of python-pytz
, too. They don't seem to like the py-redundancy.)