首页 > 解决方案 > 使用 pip 安装 keras 时出错?

问题描述

我正在尝试在 Windows 10 中使用 pip 安装 Keras 库。我已经安装了所有要求,python>=3.8,pip>=20.0.0,NumPy,pandas,matplotlib,virtualenv。但我收到以下错误。

(keras) C:\Users\namba>pip install keras
Collecting keras
  Using cached Keras-2.4.3-py2.py3-none-any.whl (36 kB)
Collecting h5py
  Using cached h5py-3.1.0.tar.gz (371 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.9.1 in c:\users\namba\keras\lib\site-packages (from keras) (1.19.4)
Collecting pyyaml
  Using cached PyYAML-5.3.1-cp38-cp38-win32.whl (199 kB)
Requirement already satisfied: scipy>=0.14 in c:\users\namba\keras\lib\site-packages (from keras) (1.5.4)
Building wheels for collected packages: h5py
  Building wheel for h5py (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\namba\keras\scripts\python.exe' 'c:\users\namba\keras\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\namba\AppData\Local\Temp\tmp0_p1fdyc'
       cwd: C:\Users\namba\AppData\Local\Temp\pip-install-k9e6wdb4\h5py
  Complete output (70 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-3.8
  creating build\lib.win32-3.8\h5py
  copying h5py\h5py_warnings.py -> build\lib.win32-3.8\h5py
  copying h5py\ipy_completer.py -> build\lib.win32-3.8\h5py
  copying h5py\version.py -> build\lib.win32-3.8\h5py
  copying h5py\__init__.py -> build\lib.win32-3.8\h5py
  creating build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\attrs.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\base.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\compat.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\dataset.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\datatype.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\dims.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\files.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\filters.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\group.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\selections.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\selections2.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\vds.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\__init__.py -> build\lib.win32-3.8\h5py\_hl
  creating build\lib.win32-3.8\h5py\tests
  copying h5py\tests\common.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\conftest.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_attribute_create.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_attrs.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_attrs_data.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_base.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_big_endian_file.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_completions.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dataset.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dataset_getitem.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dataset_swmr.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_datatype.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dimension_scales.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dims_dimensionproxy.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dtype.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_errors.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_file.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_file2.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_file_image.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_filters.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_group.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5d_direct_chunk.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5f.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5p.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5pl.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5t.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_objects.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_selections.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_slicing.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\__init__.py -> build\lib.win32-3.8\h5py\tests
  creating build\lib.win32-3.8\h5py\tests\data_files
  copying h5py\tests\data_files\__init__.py -> build\lib.win32-3.8\h5py\tests\data_files
  creating build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\test_vds\test_highlevel_vds.py -> build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\test_vds\test_lowlevel_vds.py -> build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\test_vds\test_virtual_source.py -> build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\test_vds\__init__.py -> build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\data_files\vlen_string_dset.h5 -> build\lib.win32-3.8\h5py\tests\data_files
  copying h5py\tests\data_files\vlen_string_dset_utc.h5 -> build\lib.win32-3.8\h5py\tests\data_files
  copying h5py\tests\data_files\vlen_string_s390x.h5 -> build\lib.win32-3.8\h5py\tests\data_files
  running build_ext
  Loading library to get version: hdf5.dll
  error: Unable to load dependency HDF5, make sure HDF5 is installed properly
  error: Could not find module 'hdf5.dll' (or one of its dependencies). Try using the full path with constructor syntax.
  ----------------------------------------
  ERROR: Failed building wheel for h5py
Failed to build h5py
ERROR: Could not build wheels for h5py which use PEP 517 and cannot be installed directly

我认为这个错误是由于 h5py & hdf5 安装不当引起的。我尝试使用安装它们,pip install h5py但后来遇到以下错误:

(keras) C:\Users\namba>pip install h5py
Collecting h5py
  Using cached h5py-3.1.0.tar.gz (371 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.17.5; python_version == "3.8" in c:\users\namba\keras\lib\site-packages (from h5py) (1.19.4)
Building wheels for collected packages: h5py
  Building wheel for h5py (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\namba\keras\scripts\python.exe' 'c:\users\namba\keras\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\namba\AppData\Local\Temp\tmpid2mdza_'
       cwd: C:\Users\namba\AppData\Local\Temp\pip-install-yppxk_bm\h5py
  Complete output (70 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-3.8
  creating build\lib.win32-3.8\h5py
  copying h5py\h5py_warnings.py -> build\lib.win32-3.8\h5py
  copying h5py\ipy_completer.py -> build\lib.win32-3.8\h5py
  copying h5py\version.py -> build\lib.win32-3.8\h5py
  copying h5py\__init__.py -> build\lib.win32-3.8\h5py
  creating build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\attrs.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\base.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\compat.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\dataset.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\datatype.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\dims.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\files.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\filters.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\group.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\selections.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\selections2.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\vds.py -> build\lib.win32-3.8\h5py\_hl
  copying h5py\_hl\__init__.py -> build\lib.win32-3.8\h5py\_hl
  creating build\lib.win32-3.8\h5py\tests
  copying h5py\tests\common.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\conftest.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_attribute_create.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_attrs.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_attrs_data.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_base.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_big_endian_file.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_completions.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dataset.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dataset_getitem.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dataset_swmr.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_datatype.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dimension_scales.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dims_dimensionproxy.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_dtype.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_errors.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_file.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_file2.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_file_image.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_filters.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_group.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5d_direct_chunk.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5f.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5p.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5pl.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_h5t.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_objects.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_selections.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\test_slicing.py -> build\lib.win32-3.8\h5py\tests
  copying h5py\tests\__init__.py -> build\lib.win32-3.8\h5py\tests
  creating build\lib.win32-3.8\h5py\tests\data_files
  copying h5py\tests\data_files\__init__.py -> build\lib.win32-3.8\h5py\tests\data_files
  creating build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\test_vds\test_highlevel_vds.py -> build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\test_vds\test_lowlevel_vds.py -> build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\test_vds\test_virtual_source.py -> build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\test_vds\__init__.py -> build\lib.win32-3.8\h5py\tests\test_vds
  copying h5py\tests\data_files\vlen_string_dset.h5 -> build\lib.win32-3.8\h5py\tests\data_files
  copying h5py\tests\data_files\vlen_string_dset_utc.h5 -> build\lib.win32-3.8\h5py\tests\data_files
  copying h5py\tests\data_files\vlen_string_s390x.h5 -> build\lib.win32-3.8\h5py\tests\data_files
  running build_ext
  Loading library to get version: hdf5.dll
  error: Unable to load dependency HDF5, make sure HDF5 is installed properly
  error: Could not find module 'hdf5.dll' (or one of its dependencies). Try using the full path with constructor syntax.
  ----------------------------------------
  ERROR: Failed building wheel for h5py
Failed to build h5py
ERROR: Could not build wheels for h5py which use PEP 517 and cannot be installed directly

请提出任何解决方案来克服这些错误?

标签: pythonkerasdeep-learningpiph5py

解决方案


最好使用 64 位 python3(<3.9) 来使用深度学习库(Keras、TensorFlow),因为尚未执行和发布 32 位测试。因此,请确保检查它是 64 位还是 32 位。感谢Tasnuva的帮助!


推荐阅读