安装相关依赖
# yum install wget
# yum -y install gcc
# yum -y install gcc-c++
# yum install glibc-headers
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel make
可以选装gcc 8.3.0,也可以用上边装的默认版本,下载安装包
https://mirrors.ustc.edu.cn/gnu/gcc/gcc-8.3.0/gcc-8.3.0.tar.xz
# tar xvJf gcc-8.3.0.tar.xz
# cd ~/gcc-8.3.0
# yum search bzip2
# yum install bzip2.x86_64
# ./contrib/download_prerequisites
# mkdir build-gcc-8.3.0
# cd build-gcc-8.3.0
# ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
# make -j4
# make install
安装Python3
访问Python官网 https://www.python.org/downloads/source/
下载安装包
https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
# tar -xvJf Python-3.7.4.tar.xz
# cd Python-3.7.4
# ./configure
# make && make install
若报 _ctypes 有关错误
# yum install libffi-devel -y
# make && make install
若报ssl module安装失败,用libressl替代openssl
下载最新稳定版本 2.7.4
https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.4.tar.gz
# tar -zxvf libressl-2.7.4.tar.gz
# cd libressl-2.7.4
# ./configure
# make
# sudo make install
# vim /etc/ld.so.conf.d/local.conf
添加如下内容:
/usr/local/lib
即将 /usr/local/lib 目录加入到模块加载目录。
重新加载共享模块:
# ldconfig -v
# openssl version
LibreSSL 2.7.4
回到 Python-3.7.4 目录,编辑安装文件
# vim /Modules/Setup
删除有关 ssl 编译代码的注释,共 4 行,并修改 SSL 目录为 SSL=/usr/local, 如下所示:
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
重新编译
# ./configure
# make
# make install
链接新版本Python
# unlink /usr/bin/python
# ln -s /usr/local/bin/python3 /usr/bin/python
修改yum,否则不可使用
# vim /usr/bin/yum
首行改为 #!/usr/bin/python2.7
# vim /usr/libexec/urlgrabber-ext-down
首行改为 #!/usr/bin/python2.7
Python安装完毕
开始安装TensorFlow
升级pip
# pip3 install --upgrade pip
升级setuptools
# pip3 uninstall setuptools
# pip3 install setuptools==41.0.0
安装TensorFlow CPU版本
# pip3 install tensorflow==2.0.0-beta0
或者TensorFlow GPU版本
# pip install tensorflow-gpu==2.0.0-beta0
升级libstdc.so.6
下载 libstdc++.so.6.0.21,记住一定要是这个版本,高一点低一点tensorflow都不能运行
备份旧的链接
# mv /lib64/libstdc++.so.6 /lib64/libstdc++.so.6.bak
# cp libstdc++.so.6.0.21 /lib64/
链接新的libstdc++
# ln -s /lib64/libstdc++.so.6.0.21 /lib64/libstdc++.so.6
去 https://download.csdn.net/download/qq_33160790/10241415 下载glibc-2.23.tar.bz2
# tar -xvf glibc-2.23.tar.bz2
# cd glibc-2.23
# mkdir build-glibc-2.23
# cd build-glibc-2.23
# ../configure --disable-sanity-checks --disable-werror --prefix /usr/
# make
# make install
如果发生如下错误
gawk: error while loading shared libraries: /lib64/libm.so.6: invalid ELF header
make[2]: *** [/disk1/software/gcc/glibc-2.23/build/math/stubs] Error 127
make[2]: Leaving directory `/disk1/software/gcc/glibc-2.23/math'
make[1]: *** [math/subdir_install] Error 2
make[1]: Leaving directory `/disk1/software/gcc/glibc-2.23'
# unlink /lib64/libm.so.6
# ln -s /lib64/libm-2.23.so /lib64/libm.so.6
# make install