Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 469
GhostRider Avatar asked Nov 18 '25 10:11

GhostRider


1 Answers

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.

like image 191
Shou Avatar answered Nov 20 '25 23:11

Shou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!