【问题标题】:Tensorflow on M1M1 上的张量流
【发布时间】:2021-11-05 14:06:43
【问题描述】:

导入 Tensorflow 会出现此错误

这是我的“代码”:

import tensorflow as tf

我的版本: protoc --version

libprotoc 3.15.8

pip 显示 protobuf

名称:protobuf 版本:3.19.1

张量流 2.6.0

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-64156d691fe5> in <module>
----> 1 import tensorflow as tf

~/miniforge3/envs/userenv/lib/python3.8/site-packages/tensorflow/__init__.py in <module>
     39 import sys as _sys
     40 
---> 41 from tensorflow.python.tools import module_util as _module_util
     42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
     43 

~/miniforge3/envs/userenv/lib/python3.8/site-packages/tensorflow/python/__init__.py in <module>
     38 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
     39 
---> 40 from tensorflow.python.eager import context
     41 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
     42 

~/miniforge3/envs/userenv/lib/python3.8/site-packages/tensorflow/python/eager/context.py in <module>
     30 import six
     31 
---> 32 from tensorflow.core.framework import function_pb2
     33 from tensorflow.core.protobuf import config_pb2
     34 from tensorflow.core.protobuf import rewriter_config_pb2

~/miniforge3/envs/userenv/lib/python3.8/site-packages/tensorflow/core/framework/function_pb2.py in <module>
      3 # source: tensorflow/core/framework/function.proto
      4 """Generated protocol buffer code."""
----> 5 from google.protobuf import descriptor as _descriptor
      6 from google.protobuf import message as _message
      7 from google.protobuf import reflection as _reflection

~/miniforge3/envs/userenv/lib/python3.8/site-packages/google/protobuf/descriptor.py in <module>
     45   import binascii
     46   import os
---> 47   from google.protobuf.pyext import _message
     48   _USE_C_DESCRIPTORS = True
     49 

AttributeError: module 'google.protobuf.internal.containers' has no attribute 'MutableMapping'

我正在使用 Jupyter,并且在 Apple M1 上。我使用 Miniforge,我真的不知道下一步该往哪里看。由于原生 M1 芯片,我从 Anaconda 切换到 Miniforge。

【问题讨论】:

标签: python tensorflow


【解决方案1】:

我尝试使用以下方法在我的 Macbook pro (M1) 上成功安装 tf。

conda install -c apple tensorflow-deps==2.6.0
pip install tensorflow-macos

我成功导入了tensorflow,并运行了测试脚本。

参考资料:https://blog.csdn.net/qq_43731778/article/details/122525442

【讨论】:

    【解决方案2】:

    您现在可以使用 conda 让 tensorflow 在本机工作。请按照以下顺序进行

    为 osx-arm64 创建 Conda 环境

    CONDA_SUBDIR=osx-arm64 conda create -n <env name> python=3.8 -c conda-forge
    

    您也可以使用目前支持的两个版本 3.9

    创建环境后设置默认子目录以查找 osx-arm64 包

    conda activate <env name>
    conda config --env --set subdir osx-arm64
    

    为 osx-arm64 包添加 conda-forge 通道到 env

    conda config --env --add channels conda-forge
    

    将通道优先级设置为严格,以便在安装其他软件包时默认只查看 conda-forge 通道

    conda config --env --set channel_priority strict
    

    安装所有依赖项

    conda install -c apple tensorflow-deps
    

    安装基础张量流

    SYSTEM_VERSION_COMPAT=0 python -m pip install tensorflow-macos
    

    安装 tensorflow-metal 插件

    python -m pip install tensorflow-metal
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 2019-08-02
      • 1970-01-01
      • 2020-02-08
      相关资源
      最近更新 更多