python install without pip on ubuntu python install without pip on ubuntu python-3.x python-3.x

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


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.)


I have been installing pip from the pip-get.py in Docker (Ubuntu) containers for a few years without problem. For me it is the best way to not-get pip-out-of-date warnings or (at some point, some time ago) SSL related errors.

So the second part of your answer is close, but your python install seems a bit too minimal, you need sysconfig as provided by python-distutils. You can try this rather minimal Dockerfile:

FROM ubuntu:latestMAINTAINER AnthonENV DEBIAN_FRONTEND noninteractiveRUN apt-get update && apt-get install -y \  python3 \  python3-distutils \&& apt-get clean \&& rm -rf /var/lib/apt/lists/*# this gets you the latest pipCOPY pip/get-pip.py /tmp/get-pip.pyRUN python3 /tmp/get-pip.pyRUN pip3 install pyyaml

which I ran using this Makefile:

doit:   pip/get-pip.py        docker build .pip/get-pip.py:        -@mkdir pip        curl https://bootstrap.pypa.io/get-pip.py -o pip/get-pip.py

(those need to be TAB characters on the indented lines) to make sure pip-get.py is available from the context (you can of course download it from within the Dockerfile, but that is not necessary). That ends in a succesful PyYAML install, but it will be slow.

I recommend you start using ruamel.yaml (disclaimer: I am the author of that package), by changing the last line of the Dockerfile to read:

RUN pip3 install ruamel.yaml

Apart from many bugfixes in the original PyYAML code it is based upon, ruamel.yaml supports YAML 1.2 and YAML 1.1 (replaced in 2009 and the version PyYAML supports), and installs the appropriate version from a .whl file, so you'll have the fast C loader available in your container (PyYAML doesn't do that).

You can load a YAML file using the C-loader in ruamel.yaml using:

from pathlib import Pathfrom ruamel.yaml import YAMLpath = Path('yourfile.yaml')yaml = YAML(typ='safe')data = yaml.load(path)