简体   繁体   English

使用pip安装keras时出错?

[英]Errors in installing keras using pip?

I am trying to install Keras library using pip in windows 10. I have all the requirements installed, python>=3.8, pip>=20.0.0, NumPy, pandas, matplotlib, virtualenv.我正在尝试在 Windows 10 中使用 pip 安装 Keras 库。我已安装所有要求,python>=3.8、pip>=20.0.0、NumPy、pandas、matplotlib、virtualenv。 But I'm getting the following error.但我收到以下错误。

(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

I thought this error was caused due to improper installation of h5py & hdf5.我认为这个错误是由于 h5py & hdf5 安装不当引起的。 I tried installing them using pip install h5py but then I encountered the following error:我尝试使用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

Please suggest any solutions to overcome these errors?请提出任何解决方案来克服这些错误?

It is preferred to use a 64bit python3(<3.9), to work with deep learning libraries(Keras, TensorFlow), because testings on 32bit were not yet performed and released.最好使用 64 位 python3(<3.9),与深度学习库(Keras、TensorFlow)一起使用,因为 32 位的测试尚未执行和发布。 So, Make sure you check whether it is 64 bit or 32 bit.因此,请确保检查它是 64 位还是 32 位。 Thanks to Tasnuva for helping!感谢Tasnuva的帮助!

Sometimes it happens due to old version of pip有时它是由于旧版本的pip

upgrade pip:升级点:

pip3 install --upgrade pip

then try again:然后再试一次:

pip install h5py

Note: make sure your python3.8 is 64bit注意:确保你的python3.8是64位

The following is the procedure I followed to fix the problem.以下是我用来解决问题的过程。
First, to check which version you're using:首先,检查您使用的是哪个版本:

  • look at the bottom left corner of Visual Studio Code in case you're using this IDE (you'll find something like Python vvv 32-bit )如果您正在使用此 IDE,请查看 Visual Studio Code 的左下角(您会发现类似Python vvv 32-bit
  • execute python -VV from the terminal从终端执行python -VV
    Then download and install the 64-bit version of python from here (don't forget to check Add Python vv to PATH before installing)然后从这里下载并安装64位版本的python(安装前不要忘记检查Add Python vv to PATH
    Delete the existing virtual environment (if you already have one) and create a new venv with the latest version of Python that you downloaded.删除现有的虚拟环境(如果您已经有了)并使用您下载的最新版本的 Python 创建一个新的 venv。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM