簡體   English   中英

使用pip安裝keras時出錯?

[英]Errors in installing keras using pip?

我正在嘗試在 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

請提出任何解決方案來克服這些錯誤?

最好使用 64 位 python3(<3.9),與深度學習庫(Keras、TensorFlow)一起使用,因為 32 位的測試尚未執行和發布。 因此,請確保檢查它是 64 位還是 32 位。 感謝Tasnuva的幫助!

有時它是由於舊版本的pip

升級點:

pip3 install --upgrade pip

然后再試一次:

pip install h5py

注意:確保你的python3.8是64位

以下是我用來解決問題的過程。
首先,檢查您使用的是哪個版本:

  • 如果您正在使用此 IDE,請查看 Visual Studio Code 的左下角(您會發現類似Python vvv 32-bit
  • 從終端執行python -VV
    然后從這里下載並安裝64位版本的python(安裝前不要忘記檢查Add Python vv to PATH
    刪除現有的虛擬環境(如果您已經有了)並使用您下載的最新版本的 Python 創建一個新的 venv。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM