Run TensorFlow Docker Image on Python3

About this article

It is as the title.

If you're in a hurry to conclude, clone I forked TensorFlow and check out the feature-py3 branch. After that, build and run in the tensorflow / tensorflow / tools / docker directory.

Let's proceed step by step. TensorFlow itself supports both Python2.7 and Python3.x, but Docker Image is Python2.7 only.

This article is for those who want to use Docker Image built with Python 3.x.

I'm not particular about the Python version! Those who say You can easily get started with the following command by following the Download and Setup (https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#docker-installation).

docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow

In addition, on GitHub, an issue related to this content has been posted since June 2016, but there is no movement and a comment to the effect that you know how difficult it is to respond. (Free translation) is also attached, and it seems that there are basically no plans to support it.

Support python 3.x based Tensorflow in docker image #2600

Changes to work with Python 3

If the Docker Image is not published, you can update the Dockerfile yourself and proceed.

You can easily find it by diving a little in the directory.

tensorflow/Dockerfile at master · tensorflow/tensorflow · GitHub

Basically, the only change required to run on Python 3 is the Dockerfile. Make the following changes:

Also, change the version of TensorFlow to be installed according to the Installation page with pip.

Basically this is OK.

After that, update the Kernel version on Jupyter Notebook, delete the wrong part in the sample, and finish. (I didn't get an error message when using Python 2.7, but when I changed it to 3.x, an error message was displayed, so I deleted it.)

These changes are available on GitHub Comparing tensorflow: master ... tkhm: feature-py3 · tensorflow / tensorflow You can check from.

Docker Image creation

If you want to create a Docker Image according to this change, follow the steps below. (The content is the same because I just made the one written at the beginning carefully.)

  1. Clone from https://github.com/tkhm/tensorflow/

  2. After cloning, change from master branch to feature-py3 branch with git command

  3. Go to the tensorflow / tensorflow / tools / docker directory and run the following command

    docker build --tag="localhost:tensorflow-py3" .
    docker run -it -p 8888:8888 --name tensorflowpy3 localhost:tensorflow-py3
    
  4. Access Jupyter running on docker (e.g.172.17.0.2:8888)

Note that docker build takes about 10-20 minutes depending on the network environment. Please note that those who have limited communication capacity will also need a certain amount of communication. Also, the above localhost: tensorflow-py3 (repository name: tag name) and tensorflowpy3 (container name) are optional, so change them to your liking.

Version confirmation

If you want to check if it has been successfully updated to Python3, delete the from __future__ import print_function in the first line of each sample and try it. print () is from Python 3.x, but with the one line above it is also available in Python 2.7.

Alternatively, you could directly execute code like this:

import sys
sys.version

that's all.

Recommended Posts

Run TensorFlow Docker Image on Python3
Run Tensorflow 2.x on Python 3.7
Install Python 3.6 on Docker
TensorFlow: Run data learned in Python on Android
Run Openpose on Python (Windows)
Run Python CGI on CORESERVER
Run unix command on python
Introducing TensorFlow on Ubuntu + Python 2.7
Run IPython Notebook on Docker
Try running tensorflow on Docker + anaconda
Run Tensorflow natively supported on windows
Run Python on Schedule on AWS Lambda
Run Matplotlib on a Docker container
Run headless-chrome on a Debian-based image
Run TensorFlow2 on a VPS server
Periodically run Python on Heroku Scheduler
Run servo with Python on ESP32 (Windows)
Run TensorFlow on a GPU instance on AWS
[Python] Run Flask on Google App Engine
Build CGI Server running on Python 3 on Docker
Run AzureKinect in Python on Christmas Eve.
Use cryptography library cryptography with Docker Python image
Created Ubuntu, Python, OpenCV environment on Docker
Run servomotor on Raspberry Pi 3 using python
Run Keycloak on Amazon Linux 2 without Docker
[Python] Run Headless Chrome on AWS Lambda
Run Python code on A2019 Community Edition
Run a Python web application with Docker
Run matplotlib on a Windows Docker container
Run Python in C ++ on Visual Studio 2017
Run python wsgi server on NGINX Unit
pykintone on Docker
python image processing
Python on Windows
twitter on python3
Run a Python file inside a Docker container on a remote Raspbian via PyCharm
python on mac
python at docker
Python on Windbg
Periodically run a python program on AWS Lambda
Install and run Python3.5 + NumPy + SciPy on Windows 10
Put MicroPython on Windows to run ESP32 on Python
What is wheezy in the Docker Python image?
Run Python YOLOv3 in C ++ on Visual Studio 2017
How to run MeCab on Ubuntu 18.04 LTS Python
Run Python web apps on NGINX + NGINX Unit + Flask
Run Zookeeper x python (kazoo) on Mac OS X
Run pip install on MacOS Python 3.7 or later
Run Flask on CentOS with python3.4, Gunicorn + Nginx.
Installing TensorFlow on Windows Easy for Python beginners
Run Python on Apache to view InfluxDB data
Build a Docker image containing the private repository Python library on GitHub Actions
Install Tensorflow on Mac
Python conda on cygwin
Install TensorFlow on Ubuntu
Install python on WSL
[Docker] Tutorial (Python + php)
Run Python with VBA
PyOpenGL setup on Python 3
Run Tensorflow from Jupyter Notebook on Bash on Ubuntu on Windows
Install Python on Pidora.