Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Pillow in Docker

I am not able to install python's PIL module in docker for some reason. Here's a description of what I have:

requirements.txt

Pillow
flask
redis

Dockerfile

FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py

app.py

import PIL

Commands

$ sudo docker build -t web .
Installing collected packages: Pillow, Werkzeug, MarkupSafe, Jinja2, itsdangerous, flask, redis
Successfully installed Jinja2-2.8 MarkupSafe-0.23 Pillow-2.9.0  Werkzeug-0.10.4 flask-0.10.1 itsdangerous-0.24 redis-2.10.3
---> 91dfb38bd480
Removing intermediate container 4e4ca5801814
Step 4 : CMD python app.py
 ---> Running in e71453f2fab6
 ---> d62996658bd6
 Removing intermediate container e71453f2fab6
 Successfully built d62996658bd6

$ sudo docker-compose up

Here's what I get: Output

web_1   |   File "app.py", line 1, in <module>
web_1   |     import PIL
web_1   | ImportError: No module named PIL

I thought maybe adding PIL in requirements.txt would work, but here's what happens when I build

$ sudo docker build -t web .
....
Collecting PIL (from -r requirements.txt (line 1))
Could not find a version that satisfies the requirement PIL (from -r    requirements.txt (line 1)) (from versions: )
Some externally hosted files were ignored as access to them may be  unreliable (use --allow-external PIL to allow).
No matching distribution found for PIL (from -r requirements.txt (line 1))

Any idea what should be done from here?

like image 318
arbazkhan002 Avatar asked Sep 26 '15 22:09

arbazkhan002


1 Answers

Add RUN apk add zlib-dev jpeg-dev gcc musl-dev in the Dockerfile and then add Pillow in the requirements.txt

like image 60
Nooras Fatima Ansari Avatar answered Oct 27 '22 01:10

Nooras Fatima Ansari