简体   繁体   中英

Error while installing TensorFlow with pip

While I try to install TensorFlow I get this error:

(venv) olivierskonieczny@MacBook-Pro-olivier AI % python3 -m pip install tensorflow-macos

Collecting tensorflow-macos
  Using cached tensorflow_macos-2.7.0-cp38-cp38-macosx_11_0_arm64.whl (179.0 MB)
....
....
....
Building wheels for collected packages: h5py
  Building wheel for h5py (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for h5py (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [7 lines of output]
      running bdist_wheel
      running build
      running build_py
      running build_ext
      Loading library to get build settings and version: libhdf5.dylib
      error: Unable to load dependency HDF5, make sure HDF5 is installed properly
      error: dlopen(libhdf5.dylib, 0x0006): tried: 'libhdf5.dylib' (no such file), '/usr/lib/libhdf5.dylib' (no such file), '/private/var/folders/rh/4d7_g4zj06l16r4kl40s7rcm0000gn/T/pip-install-bukptyvu/h5py_993a67c380d14b6788f3e17bb8badb62/libhdf5.dylib' (no such file), '/usr/lib/libhdf5.dylib' (no such file)
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for h5py
Failed to build h5py
ERROR: Could not build wheels for h5py, which is required to install pyproject.toml-based projects

I try to install p5py, PEP517 and still nothing works.

% pip --version
pip 22.0.2 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)

As you can see I've got newest pip version.

Im using Mac OS X newest version MacBookPro with M1

Please help me?

I have an MacBook Pro with M1 Pro chip and I had the same problem as you. For the moment the only solution I found is to use an environment with conda.

This help me: https://caffeinedev.medium.com/how-to-install-tensorflow-on-m1-mac-8e9b91d93706

Here is what I did to make it work

1. Install Xcode (few hour for me)

From the Apps Store:

https://apps.apple.com/fr/app/xcode/id497799835?mt=12

or

With command line:

xcode-select --install

2. Download Miniforge

https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh

3. In the directory where you downloaded the previous file

chmod +x Miniforge3-MacOSX-arm64.sh

4. Execute Miniforge

./Miniforge3-MacOSX-arm64.sh

Press enter, yes, enter... Install complete !

5. Turn off base environment

conda config --set auto_activate_base false

6. Create environment

conda create --name conda_tf python=3.8

7. Use the previous environment

conda activate conda_tf

8. Install tensorflow depencies

conda install -c apple tensorflow-deps

9. Install tensorflow

 pip install tensorflow-macos

To remember:

To get out of the environment:

conda deactivate

To enter from the environment:

conda activate conda_tf

I fix this by following Apple Developer Docs: https://developer.apple.com/metal/tensorflow-plugin/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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