centos7(python2.7) 安装tensorflow+keras过程
最近找到一台电脑,装了centos7,所以打算装一个keras玩啊。
主要过程如下,参考博客已在文中注明:
1. 安装centos7 , 自带python2.7,但是没有pip命令
根据(https://blog.csdn.net/boooobcsdn/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.
-
-
-
-
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
-
-
hello,tf
-
-
-
-
42
其中有个warning告警,根据(https://blog.csdn.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