Centos7 安装Python3以及安装TensorFlow

本文详细介绍了在Centos7系统中安装Python3.x和TensorFlow的过程,包括下载Python源码、配置编译环境、安装Python3.x及创建软链接,最后通过pip安装TensorFlow并验证其正确运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载Python3          https://www.python.org/getit/
两个包都可以使用,不过最好不要下载XZ格式的!!!会出现一些麻烦!!!

VersionOperating SystemDescriptionMD5 SumFile Size
Gzipped source tarballSource release 2d0fc9f3a5940707590e07f03ecb08b922540566
XZ compressed source tarballSource release 692b4fc3a2ba0d54d1495d4ead5b0b5c16872064

下载示例:

  (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完成。

 


 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值