4

I am trying to create an docker image with ubutu 16.04 as base. I want to install few python packages like pandas, flask etc. I have kept all packages in "requirements.txt". But when I am trying to build image, I am getting

Could not find a version that satisfies the requirement requests (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for requests (from -r requirements.txt (line 1))

Basically, I have not mentioned any version in "requirements.txt". I guess it should take the latest available and compatible version of that package. But for every package same issue I am getting.

My DockerFile is as follows.

FROM ubuntu:16.04

RUN apt-get update -y && \
    apt-get install -y python3-pip python3-dev build-essential cmake pkg-config libx11-dev libatlas-base-dev

# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /testing/requirements.txt

WORKDIR /testing

RUN pip3 install -r requirements.txt

and requirements.txt is.

pandas
requests
PyMySQL
Flask
Flask-Cors
Pillow
face-recognition
Flask-SocketIO

Where I am doing wrong ? Can anybody help ?

8
  • Can you try doing pip install requests and tell me what output you get Commented Nov 15, 2019 at 5:16
  • 1
    Any reason why you're using the ubuntu image? You're probably better off using the official python one instead. It'll save you the trouble of having to install python and other dependencies. Commented Nov 15, 2019 at 5:17
  • @SanilKhurana I cannot use pip, as my code requires python3. Still as random try I tried with pip also, but i got "pip: not found error" Commented Nov 15, 2019 at 5:19
  • @jayg_code : I am using ubuntu base, because in a single docker i am including angular and python both application environment. Commented Nov 15, 2019 at 5:21
  • Try doing pip3 install requests and tell me what output you get Commented Nov 15, 2019 at 5:21

3 Answers 3

5

I too ran into the same situation. I observed that, python packages is looking for the network within docker. It is thinking that, it is running in a standalone without network so its not able to locate the package. In these type of situations either

No matching distribution found

or sometimes

Retrying ...

error may occur.

I used a --network option in the docker build command like below to overcome this error where the command insists python to use the host network to download the required packages.

docker build --network=host -t tracker:latest .

Sign up to request clarification or add additional context in comments.

1 Comment

Hey even i had the same problem, the solution you give for this worked for me.. Thanks man..
0

Try using this:

RUN python3.6 -m pip install --upgrade pip \
&& python3.6 -m pip install -r requirements.txt

by using it in this way, you are specifying the version of python in which you want to search for those packages.

Change it to python3.7 if you wish to use 3.7 version.

1 Comment

or just pip3 install -r requirements.txt. Recently got this issue with not finding package, reason was that pip == python2 -m pip whereas pip3 == python3 -m pip
0

I suggest using the official python image instead. As a result, your Dockerfile will now become:

FROM python:3

WORKDIR /testing
COPY ./requirements.txt /testing/requirements.txt

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

... etc ...

Now re: Angular/Node. You have two options from here: 1) Install Angular/Node on the Python image; or 2) Use Docker's multi-stage build feature so you build the Angular and Python-specific images before merging them together. Option 2 is recommended but it would take some work. It would probably look like this:

FROM node:8 as node

# Angular-specific build

FROM python:3 as python

# Python-specific build

# Then copy your data from the Angular image to the Python one:
COPY --from=node /usr/src/app/dist/angular-docker /usr/src/app

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.