python2.7安装tensorflow_centos7(python2.7) 安装tensorflow+keras过程

最近找到一台电脑,装了centos7,所以打算装一个keras玩啊。

主要过程如下,参考博客已在文中注明:

1. 安装centos7 , 自带python2.7,但是没有pip命令

根据(https://blog..net/boooob/article/details/79969270)解决问题:

执行命令 yum -y install epel-release ;

然后再执行 yum install python-pip;

安装好后对pip进行升级 pip install --upgrade pip

2. 新建用户imap

useradd imap

passwd imap

将imap用户添加到/etc/sudoers的步骤:

root下,chmod 777/etc/sudoers;

然后vim /etc/sudoers,在root ALL=(ALL:ALL) ALL 下面添加一行imap ALL=(ALL:ALL) ALL,保存并退出;

最后修改sudoers文件权限chmod 440 /etc/sudoers

3. pip安装tf

(https://pypi.org/project/tensorflow/#files)

命令: sudo pip install tensorflow

自动下载并安装

4. 测试安装好的tf

[imap@localhost keras-work]$ python

Python 2.7.5 (default, Jul 13 2018, 13:06:57)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

>>> hello=tf.constant("hello,tf")

>>> sess=tf.Session()

2019-02-15 11:46:34.105782: I tensorflow/core/platform/cpu_feature_guard.cc:141]

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

>>> print sess.run(hello)

hello,tf

>>> a =tf.constant(10)

>>> b=tf.constant(32)

>>> print sess.run(a+b)

42

其中有个warning告警,根据(https://blog..net/zaczoom/article/details/80359185)表示,如果只是cpu版本只是部分指令用不了,会影响效率,但是本身cpu版本效率就不高,可以忽略。

5. 安装keras

根据主页(https://keras.io/zh/#_2)安装方法

预先安装可选依赖:

cuDNN (如果你计划在 GPU 上运行 Keras,建议安装)。

HDF5 和 h5py (如果你需要将 Keras 模型保存到磁盘,则需要这些)。

>> pip install h5py

graphviz 和 pydot (用于可视化工具绘制模型图)。

>> pip install pydot

其他一些依赖:scipy,

然后选择使用github源码安装:

git clone https://github.com/keras-team/keras.git

sudo python setup.py install

6.测试keras

(1)

import tensorflow

import keras

会显示使用tensorflow作为后端

(2)

./keras/examples目录下有示例程序,进入目录,输入命令:

python mnist_mlp.py

若运行成功则表示安装成功!

期间的出错:

(1)缺少python.h;因为这些库使用了c扩展,需要编译,然后又找不到头文件和静态库导致的。编译这些c库需要的依赖库由python dev提供

#centos

sudo yum -y install python-devel

#python3使用python3-dev

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值