1.下载Python3 https://www.python.org/getit/
两个包都可以使用,不过最好不要下载XZ格式的!!!会出现一些麻烦!!!
Version | Operating System | Description | MD5 Sum | File Size |
---|---|---|---|---|
Gzipped source tarball | Source release | 2d0fc9f3a5940707590e07f03ecb08b9 | 22540566 | |
XZ compressed source tarball | Source release | 692b4fc3a2ba0d54d1495d4ead5b0b5c | 16872064 |
下载示例:
(1)linux中可以直接下载
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
(2)可以下载到本地然后传到linux上。看个人喜好。
2.创建一个文件夹:mkdir /usr/local/python3
解压文件
tar -xf Python-3.6.5.tgz -C /usr/local/python3
3.解压之后有一个目录/usr/local/python3目录下有,Python 3.6.5,进入目录
cd Python-3.6.5
4.开始安装,使用编译的方法进行安装
确保已经安装以下依赖
yum install gcc-c++
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl--devel
然后执行
./configure prefix=/usr/local/python3
make && make install
创建软链接
ln -s /usr/local/Python3/bin/python3 /usr/bin/python3
ln -s /usr/local/Python3/bin/pip3 /usr/bin/pip3
5.完成后再控制台输入python3,测试一下python3 安装是否成功。
6.安装TensorFlow
pip3 install tensorflow
7.验证安装
$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-08-28 13:02:47.410873: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-28 13:02:47.410971: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-28 13:02:47.410990: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a+b))
42
>>> quit()
至此,Centos7下安装Python3.x和TensorFlow完成。