18

I have to install Python3.7 and pip3 for Python3.7 on my Docker Ubuntu18.04. I can install the 3.7, but I cannot get rid of pip3 for Python3.6:

FROM ubuntu:18.04
# ...
RUN apt-get update && apt-get install -y \
        software-properties-common
    RUN add-apt-repository ppa:deadsnakes/ppa
    RUN apt-get update && apt-get install -y \
        python3.7 \
        python3-pip
    RUN python3.7 -m pip install pip
    RUN apt-get update && apt-get install -y \
        python3-distutils \
        python3-setuptools

and I have

root@ef0c924ba7fa:/tornado_api# python3.7 --version
Python 3.7.3
root@ef0c924ba7fa:/tornado_api# pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

while it should be pip3 under /usr/lib/python3.7/

Currently, I get

root@ef0c924ba7fa:/tornado_api# which pip3
/usr/bin/pip3
root@ef0c924ba7fa:/tornado_api# readlink $(which pip3)
root@ef0c924ba7fa:/tornado_api# 
loretoparisi
  • 15,724
  • 11
  • 102
  • 146
  • 1
    What does `which pip3` return? – MTCoster Jul 04 '19 at 18:35
  • @MTCoster updated answer with details. – loretoparisi Jul 04 '19 at 18:37
  • Thanks! How about `readlink $(which pip3)`? – MTCoster Jul 04 '19 at 18:38
  • I get anything from `readlink $(which pip3)`. What is supposed to do? get the symlink? – loretoparisi Jul 04 '19 at 18:39
  • [`readlink`](https://linux.die.net/man/1/readlink) should follow a symlink if there is one – MTCoster Jul 04 '19 at 18:40
  • 1
    got it, there is no symlink basically for `pip3` I guess. – loretoparisi Jul 04 '19 at 18:40
  • You won't be able to get rid of `pip==9.0.1` for Python 3.6 in Debian/Ubuntu using `apt`, see [this bug](https://bugs.launchpad.net/ubuntu/+source/python3-defaults/+bug/1800723). `python3-pip` installs `pip` for `python3`, which happens to be Python 3.6, and `python3.7` doesn't have its own `pip` pendant. – hoefling Jul 04 '19 at 19:35
  • @hoefling thank you! Is out there a solution or a workaround? – loretoparisi Jul 04 '19 at 20:04
  • Ubuntu 19.04 has python 3.7 as the default version. You could upgrade? – Legorooj Jul 04 '19 at 21:07
  • 7
    @loretoparisi IMO Python 3 on Debian/Ubuntu is a mess right now. You can't have a useful Python 3.7 installation without pulling at least the base Python 3.6 stuff. The cleanest way I see right now for a 3.6-minimal image is not to touch `python3-pip` at all and resort to `get-pip.py`: `apt install python3.7 curl python3-distutils && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3.7 get-pip.py`. – hoefling Jul 04 '19 at 21:34
  • If you don't need any complex installations, you can simply use a `python:3.7` docker image as base. It is anyways a linux based image with all the python requirements installed. – Raj Srujan Jalem May 18 '20 at 17:11

5 Answers5

4

It looks like this has gone stale, nevertheless, I was wondering whether by simply doing a python3.7 -m pip install --upgrade pip

FROM ubuntu:18.04
# ...
RUN apt-get update && apt-get install -y \
        software-properties-common
    RUN add-apt-repository ppa:deadsnakes/ppa
    RUN apt-get update && apt-get install -y \
        python3.7 \
        python3-pip
    RUN python3.7 -m pip install pip
    RUN apt-get update && apt-get install -y \
        python3-distutils \
        python3-setuptools
    RUN python3.7 -m pip install pip --upgrade pip
Carlos RT
  • 171
  • 1
  • 10
1

Try 'sudo apt purge pip3' or 'sudo apt-get purge pip3' If that does not work then try uninstalling pip3 with pip3. (I'm not that sure how)

My next thing to try is to update pip3 with 'pip3 install pip3' (I think)

If those don't work then I don't know.

M.K
  • 1,464
  • 2
  • 24
  • 46
1

If you don't need any complex installations, you can simply use a python:3.7 docker image as base. It is anyways a linux based image with all the python requirements installed.

Explore different python images and usage: https://hub.docker.com/_/python

Eg.:

FROM python:3

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./your-daemon-or-script.py" ]

Or if your requirement needs the same ubuntu image used, you can refer to this answer: Install pip in docker

Raj Srujan Jalem
  • 613
  • 5
  • 17
1

Just reinstall

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.7 get-pip.py --force-reinstall
Leo zhang
  • 11
  • 1
1

This work fine for me...


FROM ubuntu:18.04

RUN apt-get update && apt-get install -y software-properties-common gcc && \
    add-apt-repository -y ppa:deadsnakes/ppa

RUN apt-get update && apt-get install -y python3.8 python3-distutils python3-pip python3-apt