我有特殊要求安装Python 2.7.5在Ubuntu中,我可以安装2.7.18没有任何问题
下面是我的dockerfileARG UBUNTU_VERSION=18.04
FROM ubuntu:$UBUNTU_VERSION
RUN apt-get update -y
&& apt-get install -y python2.7.x
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["python"]
但是如果我将它设置为python2.7.5
ARG UBUNTU_VERSION=18.04
FROM ubuntu:$UBUNTU_VERSION
RUN apt-get update -y
&& apt-get install -y python2.7.5
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["python"]
抛出以下错误
E: cannot find any package by regex 'python2.7.5'
我想安装Python 2.7.5以及相关的PIP,我应该怎么做?
这个版本在规范镜像中不再可用。
已于2013年发行。
因此,从那时起,让python
和pip
一起工作是具有挑战性的。
Python 2.7.5 + PIP on centos7
如果不需要ubuntu
,这可能是最简单的方法。
ARG CENTOS_VERSION=7
FROM centos:$CENTOS_VERSION
# Python 2.7.5 is installed with centos7 image
# Add repository for PIP
RUN yum install -y epel-release
# Install pip
RUN yum install -y python-pip
RUN python --version
ENTRYPOINT [ "python" ]
Python 2.7.5 on ubuntu
我已经能够从源代码安装它了
安装pip
不成功:
https://bootstrap.pypa.io/pip/2.7/get-pip.py
ARG UBUNTU_VERSION=18.04
FROM ubuntu:$UBUNTU_VERSION
ARG PYTHON_VERSION=2.7.5
# Install dependencies
# PIP - openssl version > 1.1 may be an issue (try older ubuntu images)
RUN apt-get update
&& apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev
&& apt-get clean
WORKDIR /tmp/
# Build Python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
&& tar --extract -f Python-$PYTHON_VERSION.tgz
&& cd ./Python-$PYTHON_VERSION/
&& ./configure --enable-optimizations --prefix=/usr/local
&& make && make install
&& cd ../
&& rm -r ./Python-$PYTHON_VERSION*
RUN python --version
ENTRYPOINT [ "python" ]
Python 2.7.6 + pip
Ubuntu 14.04仍然有镜像工作(多久??)。
Python包真的很接近你的期望。
你可以试着用它来运行你的脚本。
ARG UBUNTU_VERSION=14.04
FROM ubuntu:$UBUNTU_VERSION
RUN apt-get update
&& apt-get install -y python python-pip
&& apt-get clean
RUN python --version
ENTRYPOINT [ "python" ]
Python 2.7.5 + pip,不工作,但可以在ubuntu
这是我尝试过的,但没有成功。
ARG UBUNTU_VERSION=16.04
FROM ubuntu:$UBUNTU_VERSION
# Install dependencies
RUN apt-get update
&& apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev
&& apt-get clean
WORKDIR /tmp/
# Build python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
&& tar --extract -f Python-$PYTHON_VERSION.tgz
&& cd ./Python-$PYTHON_VERSION/
&& ./configure --enable-optimizations --prefix=/usr/local
&& make && make install
&& cd ../
&& rm -r ./Python-$PYTHON_VERSION*
# Build pip from source
RUN wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
&& python get-pip.py
RUN python --version
ENTRYPOINT [ "python" ]
Python 2.7.9 with pip -如注释
所示你可以使用这个dockerfile,构建包含pip的python。
ARG UBUNTU_VERSION=16.04
FROM ubuntu:$UBUNTU_VERSION
ARG PYTHON_VERSION=2.7.9
# Install dependencies
RUN apt-get update
&& apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev
&& apt-get clean
WORKDIR /tmp/
# Build Python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
&& tar --extract -f Python-$PYTHON_VERSION.tgz
&& cd ./Python-$PYTHON_VERSION/
&& ./configure --with-ensurepip=install --enable-optimizations --prefix=/usr/local
&& make && make install
&& cd ../
&& rm -r ./Python-$PYTHON_VERSION*
RUN python --version
&& pip --version
ENTRYPOINT [ "python" ]
最简单的解决方案:
sudo apt-get install libssl-dev openssl
wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
tar xzvf Python-2.7.5.tgz
cd Python-2.7.5
./configure
make
sudo make install
安装完成后设置已安装python为默认设置。