简体   繁体   English

在 M1 Mac 上的 Conda 环境中安装 Tensorflow 时 Tensorboard 安装失败

[英]Tensorboard Install Fails while Installing Tensorflow in Conda Environment on M1 Mac

I'm trying to install tensorflow on an M1 Mac.我正在尝试在 M1 Mac 上安装 tensorflow。 I've been trying to follow this tutorial to install the pre release version of tensorflow for Mac .我一直在尝试按照本教程为 Mac 安装 tensorflow 的预发布版本 From the pre-release repo:从预发布回购:

This pre-release delivers hardware-accelerated TensorFlow and TensorFlow Addons for macOS 11.0+.此预发行版提供适用于 macOS 11.0+ 的硬件加速 TensorFlow 和 TensorFlow 插件。 Native hardware acceleration is supported on M1 Macs and Intel-based Macs through Apple's ML Compute framework.通过 Apple 的 ML Compute 框架,M1 Mac 和基于 Intel 的 Mac 支持本机硬件加速。

The pre-release requires Python 3.8, so that's what I set up my conda environment with.预发行版需要 Python 3.8,这就是我设置 conda 环境的原因。

The tutorial above tries to install a previous version of tensorflow for M1 Mac, so I adjusted the commands to use the version of tensorflow for M1 Mac that I've downloaded.上面的教程尝试为 M1 Mac 安装以前版本的 tensorflow,所以我调整了命令以使用我下载的用于 M1 Mac 的 tensorflow 版本。

I've been trying to do this install in a virtual environment using Miniforge , as it is what multiple tutorials have recommended for M1 Mac installs.我一直在尝试使用Miniforge在虚拟环境中进行此安装,因为这是多个教程推荐的 M1 Mac 安装。 From the Miniforge repo:来自 Miniforge 存储库:

This repository holds a minimal installer for Conda specific to conda-forge.此存储库包含特定于 conda-forge 的最小 Conda 安装程序。 It is comparable to Miniconda可与 Miniconda 媲美


When I get to the step to install tensorboard, pip install tensorboard , the install gets as far as:当我到达安装张量板的步骤时, pip install tensorboard ,安装到:

Building wheels for collected packages: grpcio
  Building wheel for grpcio (setup.py) ... error

The errors go on for many pages, but here is the last block:许多页面上的错误 go ,但这是最后一个块:

    Traceback (most recent call last):
      File "/private/var/folders/nq/2mtcpkp51dd149_bnk1g1t340000gn/T/pip-install-ze40tjy3/grpcio_c9426269e87d4673a65bd63bd6af18ee/src/python/grpcio/commands.py", line 282, in build_extensions
        build_ext.build_ext.build_extensions(self)
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/distutils/command/build_ext.py", line 449, in build_extensions
        self._build_extensions_serial()
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/distutils/command/build_ext.py", line 474, in _build_extensions_serial
        self.build_extension(ext)
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 208, in build_extension
        _build_ext.build_extension(self, ext)
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/distutils/command/build_ext.py", line 528, in build_extension
        objects = self.compiler.compile(sources,
      File "/private/var/folders/nq/2mtcpkp51dd149_bnk1g1t340000gn/T/pip-install-ze40tjy3/grpcio_c9426269e87d4673a65bd63bd6af18ee/src/python/grpcio/_parallel_compile_patch.py", line 58, in _parallel_compile
        multiprocessing.pool.ThreadPool(BUILD_EXT_COMPILER_JOBS).map(
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/multiprocessing/pool.py", line 364, in map
        return self._map_async(func, iterable, mapstar, chunksize).get()
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/multiprocessing/pool.py", line 771, in get
        raise self._value
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/multiprocessing/pool.py", line 125, in worker
        result = (True, func(*args, **kwds))
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar
        return list(map(*args))
      File "/private/var/folders/nq/2mtcpkp51dd149_bnk1g1t340000gn/T/pip-install-ze40tjy3/grpcio_c9426269e87d4673a65bd63bd6af18ee/src/python/grpcio/_parallel_compile_patch.py", line 54, in _compile_single_file
        self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
      File "/private/var/folders/nq/2mtcpkp51dd149_bnk1g1t340000gn/T/pip-install-ze40tjy3/grpcio_c9426269e87d4673a65bd63bd6af18ee/src/python/grpcio/commands.py", line 265, in new_compile
        return old_compile(obj, src, ext, cc_args, extra_postargs,
      File "/Users/bitflow/miniforge3/envs/conda-tf-venv/lib/python3.8/distutils/unixccompiler.py", line 120, in _compile
        raise CompileError(msg)
    distutils.errors.CompileError: command 'gcc' failed with exit status 1
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/bitflow/miniforge3/envs/conda-tf-venv/bin/python3.8 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nq/2mtcpkp51dd149_bnk1g1t340000gn/T/pip-install-ze40tjy3/grpcio_c9426269e87d4673a65bd63bd6af18ee/setup.py'"'"'; __file__='"'"'/private/var/folders/nq/2mtcpkp51dd149_bnk1g1t340000gn/T/pip-install-ze40tjy3/grpcio_c9426269e87d4673a65bd63bd6af18ee/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/nq/2mtcpkp51dd149_bnk1g1t340000gn/T/pip-record-t11k_i1o/install-record.txt --single-version-externally-managed --compile --install-headers /Users/bitflow/miniforge3/envs/conda-tf-venv/include/python3.8/grpcio Check the logs for full command output.

There was an earlier step to install grpcio, that claimed to work successfully, that used the following command:有一个安装 grpcio 的较早步骤,声称可以成功运行,它使用以下命令:

pip install --upgrade -t “$env/lib/python3.8/site-packages/” --no-dependencies --force "$libs/grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl"

I tried to import tensorflow in python, without having tensorboard installed, and the only error appears to be that tensorboard is not yet installed.我尝试在 python 中导入 tensorflow,但没有安装 tensorboard,唯一的错误似乎是尚未安装 tensorboard。 This gives me some confidence that the rest of the set up went okay.这让我确信设置的 rest 运行良好。

>>> import tensorflow
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.summary API due to missing TensorBoard installation.

I double checked, and retried, the step around installing grpcio before trying again.在重试之前,我仔细检查并重试了安装 grpcio 的步骤。 While grpcio seemed to install okay again, the tensorboard install still failed in the same way.虽然 grpcio 似乎再次安装正常,但 tensorboard 安装仍然以同样的方式失败。

I'd really appreciate any help that could be offered to solve this.我真的很感激可以提供任何帮助来解决这个问题。

I ended up referencing a lot of different materials to try get my solution working.我最终参考了很多不同的材料来尝试让我的解决方案发挥作用。 There are two main materials which I can credit with my success:有两种主要材料可以归功于我的成功:

grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl is not a supported wheel on this platform.

For some reason the version of Python that you download from the website for MacOS doesnt seem to like these files, so uninstall your current version of Python (if you dont know how to do that click here ).由于某种原因,您从 MacOS 网站下载的 Python 版本似乎不喜欢这些文件,因此请卸载您当前版本的 Python(如果您不知道如何操作,请单击此处)。 And then install the Python from xcode by pasting this into your terminal.然后将 xcode 中的 Python 粘贴到您的终端中。

xcode-select --install

I had to set a few environment variables to get it to work:我必须设置一些环境变量才能让它工作:

 GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1

to make the installation process use the libraries I've already got on the system, and then the following to point it at OpenSSL installed via Homebrew:使安装过程使用我已经在系统上获得的库,然后将其指向通过 Homebrew 安装的 OpenSSL:

 CFLAGS="-I/opt/homebrew/opt/openssl/include" LDFLAGS="-L/opt/homebrew/opt/openssl/lib"

I was focused on trying to fix the issue with the building of grpcio during the tensorboard install.我专注于尝试在 tensorboard 安装期间解决构建 grpcio 的问题。 To that end, following the above links, and throwing in a restart for the fun of it, I was finally able to install tensorboard.为此,按照上面的链接,并为了好玩而重新启动,我终于能够安装 tensorboard。

Now, if I am using Python in my conda environment, I can import tensorflow and it works just fine!现在,如果我在我的 conda 环境中使用 Python,我可以导入 tensorflow 并且它工作得很好!

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

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