Building TensorFlow for CentOS 6

Just install Anaconda and install TensorFlow by running


and you’re good to go since Continuum Analytics have applied our patch.

Do NOT install TensorFlow package from conda-forge as that is for newer version of Linux distros.


The official-released binary packages of TensorFlow are built for newer version of Linux distros. Here is how to build TensorFlow binary package for CentOS 6.

Install Dependencies

Admin privilege is required here.

OpenJDK (for Bazel)

Developer Toolset (for Bazel and TensorFlow)

C++11 compatible compiler is required during the building process. Follow the instructions in this article to install Developer Toolset. It is worth noting that, in this case, installing just devtoolset-6-toolchain would be sufficient.

Python 2.7 (for TensorFlow)

This step also requires Software Collections installed. Therefore, if you’ve installed Developer Toolset by following the instructions above, you should have no problem installing these dependencies.

Build and Install Bazel

Enter Build Environment

Enter Software Collection environment with Developer Toolset.

Prepare Source Code

Method 1 (Recommended)

The standard way of compiling a release version of Bazel from source is to use a distribution archive. From version 0.4.1, bootstrapping Bazel from GitHub repository is no longer supported as only the distribution archives contain generated artifacts required for direct compilation. Download bazel-<VERSION> from the release page.

Method 2 (Only Works for Version <= 0.4.0)

Build and Install

Build TensorFlow with Bazel

Enter Build Environment

Enter Software Collection environment with Developer Toolset and Python 2.7.

Prepare Source Code

Since GNU C library version in CentOS 6 is less than 2.17, a slight modification needs to be applied before compilation.

Modify tf_extension_linkopts function in tensorflow/tensorflow.bzl from



After above modification, we can now start building!

Here we disable jemalloc when configuring — otherwise the build will fail.

Finishing Up

Finally, you will found a tensorflow-1.5.0-cp27-none-linux_x86_64.whl (filename may vary upon versions) in /tmp/tensorflow_pkg/. With this self-built binary package, we can now deploy TensorFlow to CentOS 6 by pip.

Enter Python Environment on Deployment Target

Enter Python 2.7 environment either by Software Collection or by tools like pyenv.


Depending on your environment setup, admin privilege might be needed here.

sudo clears environment variables before running commands for security reasons, causing Software Collection environment, which relies on environment variables, to dysfunction. If you are installing TensorFlow package in Software Collection environment through sudo, you might find this command helpful.

It sets up Software Collection environment variables AFTER sudo cleans them up.


  1. Installing TensorFlow from Sources – TensorFlow
  2. Compiling from source – Installing Bazel – Bazel
  3. Distribution Artifact for Bazel – Bazel
  4. Dockerfile.devel-cpu-mkl – tensorflow/tensorflow – GitHub
  5. ImportError: undefined symbol: clock_gettime #121 – tensorflow/tensorflow – GitHub
  6. Anaconda package lists – Anaconda Documentation

10 Comments for “Building TensorFlow for CentOS 6”



Hi, I followed your method and successfully intalled tensorflow on CentOS. Thank you so much! Did you try to install it with GPU support?

Hangi Kim


Dear Kuan-Yi Li
Thank you a lot for you article.
It is very helpful to me.

I suggest add the following lines
yum install python27-setuptools
scl enable devtoolset-4 python27 bash
easy_install pip

Kuan-Yi Li


Glad you found it helpful. In regard to pip, package python27 requires python27-python-setuptools and python27-python-pip, so installing python27 should get you covered.



Huge thanks! The ‘return [“-lrt”]’ is wonderful! I was finally able to make tensorflow r0.11 work on my CentOS 6.5 with glibc version 2.12.

This post seem to be the only place, which explicitly mentions that this is the fix for glibc-version related issues. Now, after understanding that this is the fix, I can see plenty of posts, mentioning this option in github-issues posts. I saw them before, but they were not looking like something related to “ImportError: /lib64/ version `GLIBC_2.14′ not found” for me…

Michael Weiner


Thank you for the post, the tip was appreciated, however i am having an issue compiling this on an HPC running CentOS 6.5 and python 2.7.12. I built bazel with no issues, but when i go to build the pip package it fails with the following:

ERROR: /root/temp/tensorflow/tensorflow/core/BUILD:1395:1: Executing genrule //tensorflow/core:version_info_gen failed: bash failed: error executing command
(cd /root/.cache/bazel/_bazel_root/b217a9ee56a7642547b5289e2480d3f7/execroot/org_tensorflow && \
exec env – \
LD_LIBRARY_PATH=/cm/shared/apps/python/2.7.12/lib:/cm/shared/apps/intel/parallelstudio/2017/compilers_and_libraries_2017/linux/mkl/lib/intel64/:/cm/shared/apps/intel/parallelstudio/2017/compilers_and_libraries_2017/linux/lib/intel64:/cm/shared/apps/gcc/4.8.2/lib:/cm/shared/apps/gcc/4.8.2/lib64:/cm/shared/apps/slurm/14.03.0/lib64/slurm:/cm/shared/apps/slurm/14.03.0/lib64 \
PATH=/cm/shared/apps/bazel/0.5.2:/cm/shared/apps/python/2.7.12/bin:/cm/shared/apps/gcc/4.8.2/bin:/cm/shared/apps/slurm/14.03.0/sbin:/cm/shared/apps/slurm/14.03.0/bin:/cm/local/apps/cluster-tools/bin:/cm/local/apps/cmd/sbin:/cm/local/apps/cmd/bin:/cm/shared/apps/cmgui:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/ibutils/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/root/bin:/opt/dell/mdstoragesoftware/mdstoragemanager/jre/bin \
/bin/bash -c ‘source external/bazel_tools/tools/genrule/; tensorflow/tools/git/ –generate tensorflow/tools/git/gen/spec.json tensorflow/tools/git/gen/head tensorflow/tools/git/gen/branch_ref “bazel-out/host/genfiles/tensorflow/core/util/”‘): Process exited with status 1.
Traceback (most recent call last):
File “tensorflow/tools/git/”, line 30, in
import argparse
ImportError: No module named argparse
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 52.002s, Critical Path: 17.53s

And i can confirm that argparse is indeed installed:
[root@cc-dclrilog51 tensorflow]# python2.7
Python 2.7.12 (default, Oct 25 2016, 10:39:13)
[GCC Intel(R) C++ gcc 4.4.7 mode] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import argparse
>>> print argparse.__version__
Does anyone have a clue how to fix this?

Kuan-Yi Li


argparse is a standard library since Python 2.7 so it is very much likely your build tool is still using CentOS 6 system built-in Python, which is Python 2.6. One of the reasons I used Software Collection environment is that it not only installs Python 2.7 but also overrides system built-in Python when enabled.

You may type which python or python -V to find out which version of Python is active before TensorFlow compilation.

To further demonstrate the difference, below is what I got from my build server.

[centos@tensorflow-centos6 ~]$ which python
[centos@tensorflow-centos6 ~]$ python -V
Python 2.6.6
[centos@tensorflow-centos6 ~]$ scl enable devtoolset-6 python27 bash
[centos@tensorflow-centos6 ~]$ which python
[centos@tensorflow-centos6 ~]$ python -V
Python 2.7.13



I tried the conda route, but I still get the version ‘GLIBC_2.16’ not found error. It seems that build is still necessary for the C++11 compatible compiler side of things?

Kuan-Yi Li


I took some time to test it out, the conda route worked fine. However, I did find a possible caveat: You should install tensorflow package only from default channel, NOT conda-forge channel. Run conda config --get channels to check whether you have any auxiliary channel enabled, and if so, priority matters.

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha loading...