无法安装 h5py

无法安装 h5py

我有 Ubuntu 16.04.5 并尝试安装 Keras。我需要 h5py 来实现这一点,但是安装时遇到了问题。当我输入:

sudo pip install h5py

我懂了:

The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting h5py
  Downloading https://files.pythonhosted.org/packages/74/5d/6f11a5fffc3d8884bb8d6c06abbee0b3d7c8c81bde9819979208ba823a47/h5py-2.8.0.tar.gz (274kB)
    100% |████████████████████████████████| 276kB 1.7MB/s
Requirement already satisfied: numpy>=1.7 in /home/nvidia/.local/lib/python3.5/site-packages (from h5py) (1.15.4)
Requirement already satisfied: six in /home/nvidia/.local/lib/python3.5/site-packages (from h5py) (1.11.0)
Installing collected packages: h5py
  Running setup.py install for h5py ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-49wsh8ku/h5py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ltnxb8_8/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-aarch64-3.5
    creating build/lib.linux-aarch64-3.5/h5py
    copying h5py/__init__.py -> build/lib.linux-aarch64-3.5/h5py
    copying h5py/version.py -> build/lib.linux-aarch64-3.5/h5py
    copying h5py/h5py_warnings.py -> build/lib.linux-aarch64-3.5/h5py
    copying h5py/highlevel.py -> build/lib.linux-aarch64-3.5/h5py
    copying h5py/ipy_completer.py -> build/lib.linux-aarch64-3.5/h5py
    creating build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/__init__.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/selections2.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/dims.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/attrs.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/base.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/datatype.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/dataset.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/files.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/compat.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/group.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/filters.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    copying h5py/_hl/selections.py -> build/lib.linux-aarch64-3.5/h5py/_hl
    creating build/lib.linux-aarch64-3.5/h5py/tests
    copying h5py/tests/__init__.py -> build/lib.linux-aarch64-3.5/h5py/tests
    copying h5py/tests/common.py -> build/lib.linux-aarch64-3.5/h5py/tests
    creating build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/__init__.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_h5t.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_dataset.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_objects.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_group.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_h5p.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_attrs.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_dimension_scales.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_datatype.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_h5f.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_slicing.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_h5d_direct_chunk_write.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_base.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_file.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_h5.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_selections.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_attrs_data.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    copying h5py/tests/old/test_file_image.py -> build/lib.linux-aarch64-3.5/h5py/tests/old
    creating build/lib.linux-aarch64-3.5/h5py/tests/hl
    copying h5py/tests/hl/__init__.py -> build/lib.linux-aarch64-3.5/h5py/tests/hl
    copying h5py/tests/hl/test_threads.py -> build/lib.linux-aarch64-3.5/h5py/tests/hl
    ...
    warning: h5py/api_types_hdf5.pxd:493:4: 'H5T_CSET_ERROR' redeclared
    warning: h5py/api_types_hdf5.pxd:494:4: 'H5T_CSET_ASCII' redeclared
    warning: h5py/api_types_hdf5.pxd:637:2: 'H5Z_filter_t' redeclared
    warning: h5py/api_types_hdf5.pxd:672:6: 'H5Z_ERROR_EDC' redeclared
    warning: h5py/api_types_hdf5.pxd:673:6: 'H5Z_DISABLE_EDC' redeclared
    warning: h5py/api_types_hdf5.pxd:674:6: 'H5Z_ENABLE_EDC' redeclared
    warning: h5py/api_types_hdf5.pxd:675:6: 'H5Z_NO_EDC' redeclared
    [ 8/22] Cythonizing /tmp/pip-install-49wsh8ku/h5py/h5py/h5ac.pyx
    /tmp/pip-install-49wsh8ku/h5py/.eggs/Cython-0.29-py3.5-linux-aarch64.egg/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-49wsh8ku/h5py/h5py/h5ac.pxd
      tree = Parsing.p_module(s, pxd, full_module_name)
    warning: h5py/api_types_hdf5.pxd:350:2: 'H5D_layout_t' redeclared
    warning: h5py/api_types_hdf5.pxd:357:2: 'H5D_alloc_time_t' redeclared
    warning: h5py/api_types_hdf5.pxd:364:2: 'H5D_space_status_t' redeclared
    warning: h5py/api_types_hdf5.pxd:370:2: 'H5D_fill_time_t' redeclared
    warning: h5py/api_types_hdf5.pxd:376:2: 'H5D_fill_value_t' redeclared
    warning: h5py/api_types_hdf5.pxd:388:7: 'H5F_close_degree_t' redeclared
    warning: h5py/api_types_hdf5.pxd:394:2: 'H5FD_mem_t' redeclared
   ...
    building 'h5py.defs' extension
    creating build/temp.linux-aarch64-3.5
    creating build/temp.linux-aarch64-3.5/tmp
    creating build/temp.linux-aarch64-3.5/tmp/pip-install-49wsh8ku
    creating build/temp.linux-aarch64-3.5/tmp/pip-install-49wsh8ku/h5py
    creating build/temp.linux-aarch64-3.5/tmp/pip-install-49wsh8ku/h5py/h5py
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DH5_USE_16_API -I./h5py -I/tmp/pip-install-49wsh8ku/h5py/lzf -I/opt/local/include -I/usr/local/include -I/home/nvidia/.local/lib/python3.5/site-packages/numpy/core/include -I/usr/include/python3.5m -c /tmp/pip-install-49wsh8ku/h5py/h5py/defs.c -o build/temp.linux-aarch64-3.5/tmp/pip-install-49wsh8ku/h5py/h5py/defs.o
    In file included from /home/nvidia/.local/lib/python3.5/site-packages/numpy/core/include/numpy/ndarraytypes.h:1821:0,
                     from /home/nvidia/.local/lib/python3.5/site-packages/numpy/core/include/numpy/ndarrayobject.h:18,
                     from /home/nvidia/.local/lib/python3.5/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                     from /tmp/pip-install-49wsh8ku/h5py/h5py/api_compat.h:26,
                     from /tmp/pip-install-49wsh8ku/h5py/h5py/defs.c:654:
    /home/nvidia/.local/lib/python3.5/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
     #warning "Using deprecated NumPy API, disable it by " \
      ^
    In file included from /tmp/pip-install-49wsh8ku/h5py/h5py/defs.c:654:0:
    /tmp/pip-install-49wsh8ku/h5py/h5py/api_compat.h:27:18: fatal error: hdf5.h: No such file or directory
    compilation terminated.
    error: command 'aarch64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-49wsh8ku/h5py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ltnxb8_8/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-49wsh8ku/h5py/

我尝试过清除缓存、升级 pip 或使用 --no-cache-dir。但都无济于事。我该怎么办?

答案1

可以使用以下命令从 Ubuntu 18.04 及更早版本中的默认存储库安装适用于 Python 2.x 的 h5py:

sudo apt install python-h5py

可以使用以下命令从所有当前支持的 Ubuntu 版本中的默认存储库安装适用于 Python 3.x 的 h5py:

sudo apt install python3-h5py  

HDF5 for Python (h5py) 是分层数据格式库版本 5 的通用 Python 接口。HDF5 是一个多功能、成熟的科学软件库,旨在快速、灵活地存储大量数据。

相关内容