Lea la pregunta detenidamente antes de cerrarla como duplicada, creo que el caso de uso es único.
Estoy tratando de crear una imagen acoplable que solo tenga instalado Python 3.7 , el problema es que si trato de instalar pip, el comando también instala Python 3.6 que no quiero .
La parte relevante del archivo docker ideal que estoy modificando es la siguiente
FROM ubuntu:18.04 # Upgrade installed packages RUN apt-get update && apt-get upgrade -y && apt-get clean # (...) # Python package management and basic dependencies RUN apt-get install -y python3.7 python3.7-dev python3.7-pip # Register the version in alternatives RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1 # Set python 3 as the default python RUN update-alternatives --set python /usr/bin/python3.7 # Upgrade pip to latest version RUN python -m ensurepip --upgrade # (...)Esto fallaría ya que python3.7-pip no parece existir; solo python3-pip lo hace, que es lo que instala python 3.6 por alguna razón.
Intenté no instalar pip en absoluto y hacerlo manualmente, así
# (...) RUN apt-get install -y python3.7 python3.7-dev # (...) RUN curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py RUN python get-pip.py pip --no-setuptools --no-wheelQue falla con este error:
Traceback (most recent call last): File "get-pip.py", line 21492, 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/tmpbez2vju9/pip.zip/pip/_internal/__init__.py", line 40, in <module> File "/tmp/tmpbez2vju9/pip.zip/pip/_internal/cli/autocompletion.py", line 8, in <module> File "/tmp/tmpbez2vju9/pip.zip/pip/_internal/cli/main_parser.py", line 8, in <module> File "/tmp/tmpbez2vju9/pip.zip/pip/_internal/cli/cmdoptions.py", line 14, in <module> ModuleNotFoundError: No module named 'distutils.util'Nuevamente, la instalación de python3-distutils hace que python 3.6 aparezca en el sistema
Entonces, ¿hay alguna manera de instalar SOLO un python 3.7 completamente funcional en ubuntu 18.04, SIN tener que instalar python 3.6?
En caso de que alguien más esté de acuerdo con la instalación de Python3.6 como efecto secundario (python3.7-distutils lo presenta como lo señala OP). Esto instalará Python3.7 por defecto y tendrá el último pip disponible usando su instalación de python3.7
FROM ubuntu:18.04 # Upgrade installed packages RUN apt-get update && apt-get upgrade -y && apt-get clean # (...) # Python package management and basic dependencies RUN apt-get install -y curl python3.7 python3.7-dev python3.7-distutils # Register the version in alternatives RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1 # Set python 3 as the default python RUN update-alternatives --set python /usr/bin/python3.7 # Upgrade pip to latest version RUN curl -s https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ python get-pip.py --force-reinstall && \ rm get-pip.py # (...)Veo dos opciones:
o
La solución de @donhector tiene dos problemas sutiles:
ppa:deadsnakes para obtener versiones más nuevaspython , se rompe la convención de que python se usa para Python 2.x. Esto podría romperse, consulte ¿Cómo actualizar las alternativas a Python 3 sin romperse?Una solución sin estos problemas es:
FROM ubuntu:18.04 # Upgrade installed packages RUN apt update && apt upgrade -y && apt clean # install python 3.7.10 (or newer) RUN apt update && \ apt install --no-install-recommends -y build-essential software-properties-common && \ add-apt-repository -y ppa:deadsnakes/ppa && \ apt install --no-install-recommends -y python3.7 python3.7-dev python3.7-distutils && \ apt clean && rm -rf /var/lib/apt/lists/* # Register the version in alternatives (and set higher priority to 3.7) RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2 # Upgrade pip to latest version RUN curl -s https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ python3 get-pip.py --force-reinstall && \ rm get-pip.py