Can't install tensorflow-macos (M1)

Dear all,

I'm unable to install tensorflow-macos, after updating to macOS Monterey(12.0 Beta). According to the last instructions from tensorflow/apple (https://developer.apple.com/metal/tensorflow-plugin/), I'm using miniforge conda, create a blank environment and then do conda install -c apple tensorflow-deps, which runs without any error or warning. Then when I try to do the following, everything breaks.

python -m pip install tensorflow-macos
  • Tried with python3.8 with the following error (summary, not the full logs):

     distutils.errors.CompileError: command 'gcc' failed with exit status 1
      
    ----------------------------------------
    ERROR: Failed building wheel for grpcio
    
  • Tried with python3.9 with the following error (summary, not the full logs):

      distutils.errors.CompileError: command '/usr/bin/clang' failed with exit code 1
    
    ----------------------------------------
    ERROR: Failed building wheel for grpcio
    
  • Tried with force reinstall and no-cache-dir (python -m pip install tensorflow-macos --no-cache-dir --force-reinstall) with the following error :

    ERROR: Command errored out with exit status 1: /Users/machine/miniforge3/envs/tf38/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-djre1j5j/numpy_48546adcbc9d4c558a4dc32a8e607649/setup.py'"'"'; __file__='"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-djre1j5j/numpy_48546adcbc9d4c558a4dc32a8e607649/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-record-343ln54c/install-record.txt --single-version-externally-managed --prefix /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-build-env-1fyu7c9t/normal --compile --install-headers /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-build-env-1fyu7c9t/normal/include/python3.8/numpy Check the logs for full command output.
      ----------------------------------------
    WARNING: Discarding https://files.pythonhosted.org/packages/a7/81/20d5d994c91ed8347efda90d32c396ea28254fd8eb9e071e28ee5700ffd5/h5py-3.1.0.tar.gz#sha256=1e2516f190652beedcb8c7acfa1c6fa92d99b42331cbef5e5c7ec2d65b0fc3c2 (from https://pypi.org/simple/h5py/) (requires-python:>=3.6). Command errored out with exit status 1: /Users/machine/miniforge3/envs/tf38/bin/python /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-standalone-pip-nmsgrvml/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-build-env-1fyu7c9t/normal --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'numpy==1.12; python_version == "3.6"' 'Cython>=0.29; python_version < "3.8"' 'numpy==1.14.5; python_version == "3.7"' 'numpy==1.19.3; python_version >= "3.9"' 'numpy==1.17.5; python_version == "3.8"' pkgconfig 'Cython>=0.29.14; python_version >= "3.8"' Check the logs for full command output.
    ERROR: Could not find a version that satisfies the requirement h5py~=3.1.0 (from tensorflow-macos) (from versions: 2.2.1, 2.3.0b1, 2.3.0, 2.3.1, 2.4.0b1, 2.4.0, 2.5.0, 2.6.0, 2.7.0rc2, 2.7.0, 2.7.1, 2.8.0rc1, 2.8.0, 2.9.0rc1, 2.9.0, 2.10.0, 3.0.0rc1, 3.0.0, 3.1.0, 3.2.0, 3.2.1, 3.3.0, 3.4.0)
    ERROR: No matching distribution found for h5py~=3.1.0

Could anyone point me out any solution, I'm really desperate here, as my work is completely stuck because of this. Thanks in advance.

Accepted Answer

I just did it with python "3.9.1" and only "--no-cache-dir". I hope that also works for you.

  • This also worked for me! Could you please explain how did you get to the working combination python3.9.1 and python -m pip install tensorflow-macos --no-cache-dir?

Add a Comment

Answers

I just did it with python "3.9.1" and only "--no-cache-dir". I hope that also works for you.

  • This also worked for me! Could you please explain how did you get to the working combination python3.9.1 and python -m pip install tensorflow-macos --no-cache-dir?

Add a Comment

Please try specifying tensorflow-deps version in a fresh conda environment like conda install -c apple tensorflow-deps==2.5.0

  • This doesn't work for me. Created fresh conda environment, then conda install -c apple tensorflow-deps==2.5.0, then when python -m pip install tensorflow-macosgot the same error (this is just the final part of the errors): Traceback (most recent call last): File "/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-25u3hpzs/grpcio_14e511c33ab9483dbc8eb10bd70d4a4b/src/python/grpcio/commands.py", line 285, in build_extensions build_ext.build_ext.build_extensions(self) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/command/build_ext.py", line 449, in build_extensions self._build_extensions_serial() File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/command/build_ext.py", line 474, in _build_extensions_serial self.build_extension(ext) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 203, in build_extension if ext._needs_stub: AttributeError: 'Extension' object has no attribute '_needs_stub'

    During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-25u3hpzs/grpcio_14e511c33ab9483dbc8eb10bd70d4a4b/setup.py", line 525, in <module> setuptools.setup( File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup return distutils.core.setup(**attrs) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/core.py", line 148, in setup dist.run_commands() File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/dist.py", line 966, in run_commands self.run_command(cmd) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/dist.py", line 985, in run_command cmd_obj.run() File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/site-packages/setuptools/command/install.py", line 61, in run return orig.install.run(self) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/command/install.py", line 546, in run self.run_command('build') File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/cmd.py", line 313, in run_command self.distribution.run_command(command) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/dist.py", line 985, in run_command cmd_obj.run() File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/command/build.py", line 135, in run self.run_command(cmd_name) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/cmd.py", line 313, in run_command self.distribution.run_command(command) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/dist.py", line 985, in run_command cmd_obj.run() File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 79, in run _build_ext.run(self) File "/Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/distutils/command/build_ext.py", line 340, in run self.build_extensions() File "/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-25u3hpzs/grpcio_14e511c33ab9483dbc8eb10bd70d4a4b/src/python/grpcio/commands.py", line 288, in build_extensions support.diagnose_build_ext_error(self, error, formatted_exception) File "/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-25u3hpzs/grpcio_14e511c33ab9483dbc8eb10bd70d4a4b/src/python/grpcio/support.py", line 117, in diagnose_build_ext_error diagnostic(build_ext, error) File "/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-25u3hpzs/grpcio_14e511c33ab9483dbc8eb10bd70d4a4b/src/python/grpcio/support.py", line 96, in diagnose_attribute_error raise commands.CommandError( commands.CommandError: We expect a missing `_needs_stub` attribute from older versions of setuptools. Consider upgrading setuptools. ----------------------------------------

    Rolling back uninstall of grpcio Moving to /Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/site-packages/grpc/ from /Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/site-packages/~rpc Moving to /Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/site-packages/grpcio-1.34.1.dist-info/ from /Users/machine/miniforge3/envs/tfdeps250/lib/python3.9/site-packages/~rpcio-1.34.1.dist-info ERROR: Command errored out with exit status 1: /Users/machine/miniforge3/envs/tfdeps250/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-25u3hpzs/grpcio_14e511c33ab9483dbc8eb10bd70d4a4b/setup.py'"'"'; file='"'"'/private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-install-25u3hpzs/grpcio_14e511c33ab9483dbc8eb10bd70d4a4b/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /private/var/folders/0k/hz9yngm56nz1htdc3c3t3d0c0000gn/T/pip-record-57rsb0gc/install-record.txt --single-version-externally-managed --compile --install-headers /Users/machine/miniforge3/envs/tfdeps250/include/python3.9/grpcio Check the logs for full command output.

  • Hi there,

    Looks like python packages incompatibility issue. I would suggest creating a new/fresh conda environment (looks like conda is getting confused with different python packages, conda --force-reinstall didn't work for me) and following the install steps to get the latest TensorFlow or see commands (option #2) to install TensorFlow 2.5. If you don't specify any versions, you'll get all the latest versions by default (currently these are tensorflow-deps==2.6, tensorflow-macos==2.6, tensorflow-metal==0.2.0), which is recommended to use with macOS 12.0+ and is supported on both python 3.8 and python 3.9.

    Option #2 To be able to use older versions, please be specific during the install: conda install -c apple tensorflow-deps==2.5.0 python -m pip install tensorflow-macos==2.5.0 python -m pip install tensorflow-metal==0.1.2 Hope that helps!

Add a Comment