GhostRider
GhostRider

Reputation: 2170

Docker: can't import tensorflow in python3 but can in python2 following dockerfile build

I have a very basic dockerfile as follows:

FROM gcr.io/tensorflow/tensorflow:latest-gpu

FROM python:3.5

RUN pip install opencv-python

RUN apt-get update && apt-get install -y libsm6 libxext6 libxrender-dev

RUN pip install skll

RUN pip install keras

RUN pip install imutils

ADD . /model1

WORKDIR /model1

VOLUME ["/model1/data", "/model1/notebooks"]

I have been learning docker for a day so I accept that this probably breaks best practices.

My question is this - once I build this and run the container and then open python and run

 import tensorflow

I get

 ImportError: No module named 'tensorflow'

If I don't include python 3.5, when I open up python its version 2.7 and tensorflow is imported properly. How can I import tensorflow using python 3 and specify this in the dockerfile

Upvotes: 3

Views: 976

Answers (1)

Shou
Shou

Reputation: 2009

If you wish to use Python 3, you're going to have to use the Python 3 docker image, in your case it would be:

FROM tensorflow/tensorflow:latest-gpu-py3

You can see all the py3 tags here. There's also an issue about this, but the tl;dr is that the image size is too big if it were to support both Python 2 and 3, hence separate py3 tags.

Upvotes: 2

Related Questions