【问题标题】:Not able to install packages that rely on Tensorflow on Mac M1无法在 Mac M1 上安装依赖于 Tensorflow 的软件包
【发布时间】:2023-03-12 11:56:01
【问题描述】:

我按照 Apple 的以下指南成功地在我的带有 M1 芯片的 MacBook 上安装了 Tensorflow 2.7.0:https://developer.apple.com/metal/tensorflow-plugin/

我现在想在依赖于 Tensorflow >=1.15.2 的项目中安装一个包 (ethnicolr)。这不应该是一个问题,但遗憾的是。

requirements.txt 我的项目

pandas==1.3.4
ethnicolr==0.4.0

requirements.txt 的种族:

tensorflow>=1.15.2

运行pip install -r requirements.txt 产生

错误:找不到满足要求的版本 tensorflow>=1.15.2(来自种族)(来自版本:无)错误:无 找到 tensorflow>=1.15.2

的匹配分布

运行pip list 显示,Tensorflow 已安装。但它不叫tensorflow,而是tensorflow-macos或tensorflow-metal。

tensorboard             2.7.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit  1.8.0
tensorflow-estimator    2.7.0
tensorflow-macos        2.7.0
tensorflow-metal        0.3.0

这里有什么解决方案?必须有更多符合 Tensorflow 要求的软件包...

【问题讨论】:

  • 不知道tensorflow官方是否支持M1...有没有试过that这样的指南?
  • 是的,我尝试了多种方法。而且我能够安装 Tensorflow。问题是依赖项被称为“tensorflow-macos”,但 ethicolr 依赖于“tensorflow”,我认为这会引发错误。我不确定在这里做什么。
  • 什么返回which python命令?
  • 它返回/Users/olespaarmann/mambaforge/envs/diversity_scraper/bin/python。所以澄清一下:我可以安装 TensorFlow,但不能安装 M1 优化版本。或者,更准确地说:我也可以安装 M1 优化版本,但其他软件包无法识别我安装了 TensorFlow。我的猜测是因为这个包叫做tensorflow-macos。

标签: python tensorflow pip apple-m1


【解决方案1】:

所以我让它运行。我不确定这是否理想,但我正在分享我的解决方案,以帮助遇到同样问题的任何人。我使用 conda / mambaforge 在虚拟环境中安装了 tensorflow 2.6.0。我选择了2.6.0,因为2.5.2 不适用于M1 并且2.5.0 不起作用。您可以阅读有关安装 Mamaforge here 的信息。之后,我用

安装了Tensorflow
conda install tensorflow==2.6.0

我还在我自己项目的requirements.txt 中将pandas 版本设置为pandas>1.2.3(与ethnicolr 相同)。这解决了熊猫1.3.3。

接下来,我必须解决与种族的依赖问题,因为种族需要 tensorflow 2.5.2。我通过分叉Ethnolr repo 并创建一个分支来做到这一点,我在requirements.txt 和setup.py 中将tensorflow 版本固定到2.6.0。你可以在here 上找到这个分支。为了使用这个 github 分支,我将requirements.txt 中的行更改为:

git+https://github.com/ospaarmann/ethnicolr.git@apple_m1_support_tensorflow_2_6_0#egg=ethnicolr

现在我遇到了与 numpy 的依赖项不匹配的问题。它在this StackOverflow thread 中有描述。发生的事情是导入 pandas 或种族会抛出这个错误:

>>> from ethnicolr import census_ln, pred_census_ln, pred_wiki_name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/ethnicolr/__init__.py", line 2, in <module>
    from ethnicolr.census_ln import census_ln
  File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/ethnicolr/census_ln.py", line 6, in <module>
    import pandas as pd
  File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/__init__.py", line 22, in <module>
    from pandas.compat import (
  File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/compat/__init__.py", line 15, in <module>
    from pandas.compat.numpy import (
  File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/compat/numpy/__init__.py", line 7, in <module>
    from pandas.util.version import Version
  File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/util/__init__.py", line 1, in <module>
    from pandas.util._decorators import (  # noqa
  File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/util/_decorators.py", line 14, in <module>
    from pandas._libs.properties import cache_readonly  # noqa
  File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/_libs/__init__.py", line 13, in <module>
    from pandas._libs.interval import Interval
  File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

这里的解决方案是忽略依赖问题并手动安装更新版本的numpy。当我在requirements.txt 中设置 numpy 版本时它不起作用,因为这会引发依赖错误:

ERROR: Cannot install numpy>=1.20.0 and tensorflow==2.6.0 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested numpy>=1.20.0
    tensorflow 2.6.0 depends on numpy~=1.19.2

所以我只是用python -m pip install numpy==1.20.0 安装了它。现在一切似乎都正常了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-17
    • 2022-06-11
    • 2021-06-18
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    相关资源
    最近更新 更多