PYNQ

PYNQ-Z2安装keras库的方法

2019-01-28  本文已影响7人  爱阳阳963

PYNQ-Z2是基于armv7l平台,使用pip3直接安装keras时会报错,如下:

In file included from /tmp/pip-build-taykg8ym/h5py/h5py/defs.c:528:0: /tmp/pip-build-taykg8ym/h5py/h5py/api_compat.h:27:10: fatal error: hdf5.h: No such file or directory #include "hdf5.h" ^~~~~~~~ compilation terminated. error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1 ---------------------------------------- Failed building wheel for h5py Running setup.py clean for h5pyFailed to build h5pyInstalling collected packages: h5py, keras-applications, keras-preprocessing, keras Running setup.py install for h5py ... \

提示未找到“hdf5.h”这个头文件,网上有相关的解决方案提到需要安装python3-dev,然而:

root@pynq:/home/xilinx# apt-get install python3-dev     
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-dev is already the newest version (3.6.5-3).
0 upgraded, 0 newly installed, 0 to remove and 333 not upgraded.

后又参考:https://blog.csdn.net/xue_wenyuan/article/details/52037121
需要先更改安装配置文件,更改include路径,但是在我的系统下并不存在这样的目录,/usr/local/include下什么都没有,然后参考https://www.jianshu.com/p/6189d6b30fb8后发现需要先安装 libhdf5-dev

sudo apt-get install libhdf5-dev

安装后会在/usr/local/include/hdf5/serial目录下产生大量头文件

root@pynq:/usr/include/hdf5/serial# ls
H5AbstractDs.h  H5Epubgen.h          H5Gpublic.h      H5PLpublic.h
H5ACpublic.h    H5Epublic.h          H5Group.h        h5p.mod
h5a.mod         H5Exception.h        H5IdComponent.h  H5Ppublic.h
H5api_adpt.h    H5f90i_gen.h         h5im.mod         H5PredType.h
H5Apublic.h     H5f90i.h             h5i.mod          H5PropList.h
H5ArrayType.h   H5FaccProp.h         H5IMpublic.h     H5PTpublic.h

然后从github下载h5py源码进行安装,下载地址:https://github.com/h5py/h5py/releases

root@pynq:/home/xilinx/install/Keras/h5py-2.9.0# python3 setup.py install
running install
running bdist_egg
.
.
.
Adding numpy 1.13.3 to easy-install.pth file

Using /usr/lib/python3/dist-packages
Finished processing dependencies for h5py==2.9.0

然后python下import h5py成功

root@pynq:/home/xilinx/# python3
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import h5py
>>> 

接下来安装keras库,import成功

root@pynq:/home/xilinx# pip3 install Keras-2.2.4-py2.py3-none-any.whl
Processing ./Keras-2.2.4-py2.py3-none-any.whl
Collecting keras-applications>=1.0.6 (from Keras==2.2.4)
  Using cached https://files.pythonhosted.org/packages/3f/c4/2ff40221029f7098d58f8d7fb99b97e8100f3293f9856f0fb5834bef100b/Keras_Applications-1.0.6-py2.py3-none-any.whl
Requirement already satisfied: six>=1.9.0 in /usr/lib/python3/dist-packages (from Keras==2.2.4)
Requirement already satisfied: numpy>=1.9.1 in /usr/lib/python3/dist-packages (from Keras==2.2.4)
Requirement already satisfied: scipy>=0.14 in /usr/lib/python3/dist-packages (from Keras==2.2.4)
Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from Keras==2.2.4)
Requirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages/h5py-2.9.0-py3.6-linux-armv7l.egg (from Keras==2.2.4)
Collecting keras-preprocessing>=1.0.5 (from Keras==2.2.4)
  Using cached https://files.pythonhosted.org/packages/fc/94/74e0fa783d3fc07e41715973435dd051ca89c550881b3454233c39c73e69/Keras_Preprocessing-1.0.5-py2.py3-none-any.whl
Installing collected packages: keras-applications, keras-preprocessing, Keras
Successfully installed Keras-2.2.4 keras-applications-1.0.6 keras-preprocessing-1.0.5

root@pynq:/home/xilinx# python3
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
>>> 
>>> 
上一篇下一篇

猜你喜欢

热点阅读