Just install Anaconda and install TensorFlow by running
conda install tensorflow
or
conda install tensorflow-gpu
and you’re good to go since Continuum Analytics have applied our patch.
Note:
Do NOT install TensorFlow package from conda-forge as that is for newer version of Linux distros.
Introduction
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)
yum install java-1.8.0-openjdk-devel
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.
yum install python27 python27-numpy python27-python-devel python27-python-wheel
Build and Install Bazel
Enter Build Environment
Enter Software Collection environment with Developer Toolset.
scl enable devtoolset-6 bash
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>-dist.zip
from the release page.
# download distribution archive wget https://github.com/bazelbuild/bazel/releases/download/0.9.0/bazel-0.9.0-dist.zip unzip bazel-0.9.0-dist.zip -d bazel-0.9.0-dist cd bazel-0.9.0-dist
Method 2 (Only Works for Version <= 0.4.0)
# clone source code repository git clone https://github.com/bazelbuild/bazel.git cd bazel # select version (optional) git checkout 0.4.0
Build and Install
# compile ./compile.sh # install mkdir -p ~/bin cp output/bazel ~/bin/ # exit from Software Collection environment exit
Build TensorFlow with Bazel
Enter Build Environment
Enter Software Collection environment with Developer Toolset and Python 2.7.
scl enable devtoolset-6 python27 bash
Prepare Source Code
# clone source code repository git clone https://github.com/tensorflow/tensorflow.git cd tensorflow # select version (optional) git checkout v1.5.0
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
def tf_extension_linkopts(): return [] # No extension link opts
to
def tf_extension_linkopts(): return ["-lrt"]
Build
After above modification, we can now start building!
Here we disable jemalloc when configuring — otherwise the build will fail.
# configure workspace export \ PYTHON_BIN_PATH=/opt/rh/python27/root/usr/bin/python \ PYTHON_LIB_PATH=/opt/rh/python27/root/usr/lib/python2.7/site-packages \ TF_NEED_JEMALLOC=0 \ TF_NEED_GCP=0 \ TF_NEED_HDFS=0 \ TF_NEED_S3=0 \ TF_ENABLE_XLA=0 \ TF_NEED_GDR=0 \ TF_NEED_VERBS=0 \ TF_NEED_OPENCL=0 \ TF_NEED_CUDA=0 \ TF_NEED_MPI=0 \ CC_OPT_FLAGS="-march=native" ./configure # build ~/bin/bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg # exit from Software Collection environment exit
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.
# by Software Collection scl enable python27 bash # or by pyenv pyenv shell anaconda2-5.0.1
Install
Depending on your environment setup, admin privilege might be needed here.
pip install tensorflow-1.5.0-cp27-none-linux_x86_64.whl
Note:
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.
sudo scl enable python27 -- pip install tensorflow-1.5.0-cp27-none-linux_x86_64.whl
It sets up Software Collection environment variables AFTER sudo
cleans them up.
References
- Installing TensorFlow from Sources – TensorFlow
- Compiling from source – Installing Bazel – Bazel
- Distribution Artifact for Bazel – Bazel
- Dockerfile.devel-cpu-mkl – tensorflow/tensorflow – GitHub
- ImportError: undefined symbol: clock_gettime #121 – tensorflow/tensorflow – GitHub
- Anaconda package lists – Anaconda Documentation
Hi, I followed your method and successfully intalled tensorflow on CentOS. Thank you so much! Did you try to install it with GPU support?
Glad you found it helpful. I didn’t install TensorFlow with GPU support since I currently don’t have compatible hardware at hand. However, I believe it should be easy if you want GPU feature enabled. Just install CUDA and build the pip package with GPU support (which means adding
--config=cuda
to the build command).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
Glad you found it helpful. In regard to
pip
, packagepython27
requirespython27-python-setuptools
andpython27-python-pip
, so installingpython27
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/libc.so.6: version `GLIBC_2.14′ not found” for me…
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/genrule-setup.sh; tensorflow/tools/git/gen_git_source.py –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/version_info.cc”‘): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
Traceback (most recent call last):
File “tensorflow/tools/git/gen_git_source.py”, 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__
1.1
Does anyone have a clue how to fix this?
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
orpython -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
/usr/bin/python
[centos@tensorflow-centos6 ~]$ python -V
Python 2.6.6
[centos@tensorflow-centos6 ~]$ scl enable devtoolset-6 python27 bash
[centos@tensorflow-centos6 ~]$ which python
/opt/rh/python27/root/usr/bin/python
[centos@tensorflow-centos6 ~]$ python -V
Python 2.7.13
hi all, I obtained tensorflow working with GPU using devtoolset-4 instead of devtoolset-6.
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?
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.Thank you for the great article. It really helped me to TensorFlow on CentOS successfully