简体   繁体   English

使用特定的 python 版本安装 pip

[英]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. 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 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我试图通过python-pip更改python3-pip pip 但是当我运行它时它给了我以下错误

E: Unable to locate package python-pip 

I've tried a lot of solutions but always the same problem我尝试了很多解决方案,但总是同样的问题

Outside of Docker, if python3.6 is the python you need, you can do: python3.6 -m pip install在 Docker 之外,如果python3.6是你需要的 python,你可以这样做: 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 ).在 Docker 现在显然python3指向 Python 3.8 所以你必须首先安装python3.6并找出如何调用它( python3.6python3 )。 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. 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.或者,如果你很幸运,你可能会找到一个现成的 Python3.6 Docker package ,它适用于你,并且apt-get install它而不是python3 ,就像你现在做的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM