Amor.o
Amor.o

Reputation: 540

Install pip with specefic python version

I am building a ubuntu docker image that is going to run my python application, and I have some libraries that require python <= 3.6 to work otherwise it will throw errors.

My problem is that when I install pip, it will always automatically use python 3.8, and I'm not sure how to let pip use an older version of python, this is the installation in my Dockerfile

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y software-properties-common && \ 
    add-apt-repository ppa:deadsnakes/ppa && \
    apt-add-repository universe && \
    apt-get update && \
    apt-get install -y \
    libmysqlclient-dev \
    netcat \
    python3 \
    python-dev \
    build-essential \
    python3-setuptools \
    python3-pip \
    supervisor && \
    pip install -U pip setuptools && \
   rm -rf /var/lib/apt/lists/*

I tried to change python3-pip by just python-pip but when I run it it gives me the following error

E: Unable to locate package python-pip 

I've tried a lot of solutions but always the same problem

Upvotes: 0

Views: 72

Answers (1)

Python Hunter
Python Hunter

Reputation: 2146

Outside of Docker, if python3.6 is the python you need, you can do: python3.6 -m pip install

In Docker right now obviously python3 is pointing to Python 3.8 so you must first install python3.6 and find out how to call it (python3.6 or python3). You might need to compile it from source and probably create some symbolic link. This can get very ugly to do inside a Docker, but you can try to write a shell script with all commands and to run the shell script inside a Docker. Or if you are lucky you may find a ready Python3.6 Docker package that works for you and apt-get install it instead of python3 the same way as you do now.

Upvotes: 1

Related Questions