【问题标题】:numpy build fail in M1 Big sur 11.1M1 Big sur 11.1 中的 numpy 构建失败
【发布时间】:2021-03-27 21:53:52
【问题描述】:

我使用的是运行 Big Sur 11.1 的 MacBook m1,我已经安装了 Xcode-commandline-tools 12.3 版,它已经安装了 python3.8.5pip3 .python3 和 pip 是本机应用程序,即它们在 ARM 中运行

pip3版本20.3.3

python3版本3.8.5

setuptools版本51.0.0

wheel版本0.36.2

当我输入python3 -m pip install numpy

输出是:

Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
  Using cached numpy-1.19.4.zip (7.3 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Building wheels for collected packages: numpy
  Building wheel for numpy (PEP 517): started
sandeep@Sandeeps-Air ~ % cat a
Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
  Using cached numpy-1.19.4.zip (7.3 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Building wheels for collected packages: numpy
  Building wheel for numpy (PEP 517): started
  Building wheel for numpy (PEP 517): finished with status 'error'
Failed to build numpy

并且有一个非常大的errors列表

M1 仍然不支持 numpy 还是我做错了?

【问题讨论】:

    标签: python-3.x macos numpy


    【解决方案1】:

    是的,stable 似乎仍然不支持 numpy,但如果您准备好使用 unstable 版本,请尝试以下命令:

    pip3 install numpy --compile --pre
    

    这将从不稳定的分支重新编译所有必要的代码。

    为我工作。

    【讨论】:

    • 这让我更接近于我尝试过的其他任何东西,但我最终还是得到了ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly。啊!
    • 也许--no-use-pep517 能解决问题? python.org/dev/peps/pep-0517
    • --no-use-pep517 选项对我不起作用,我得到了与 John Laundun 相同的结果。
    • 它对我有用。我认为问题在于您应该使用默认的 xcode cli python。此时的版本是3.8
    • 这对我不起作用!无论我做什么,它都说同样的话! ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly。我正在使用 Python v3.9,但没有任何效果!
    【解决方案2】:

    试试这个,因为我可以使用这种方法安装 numpy。

    1. brew install openblas(使用本地自制软件而不是在 Rosetta 2 下运行)
    2. OPENBLAS="$(brew --prefix openblas)" pip3 install numpy

    【讨论】:

    • 这对我不起作用,失败并出现错误 ERROR: Command errored out with exit status 1: /opt/homebrew/opt/python@3.9/bin/python3.9 /opt/homebrew/ lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/gz/p5bntj6n0tsbwm355mj3gb640000gn/T/tmpn9lk223d 检查日志以获取完整的命令输出。
    • 尝试使用命令行工具安装python 3.8而不是brew安装python 3.9
    【解决方案3】:

    我的全新 Mac Mini 遇到了完全相同的问题。花了一个下午reading this issue on github,终于成功了。但是,它似乎只适用于with v1.20.0rc2 或以上...

    长话短说,这些是我为使其工作而采取的步骤:

    pip3 install Cython
    git clone https://github.com/numpy/numpy.git 
    cd numpy
    pip3 install . --no-binary :all: --no-use-pep517
    

    之后,我可以 cd 进入我的 virtualenv 并导入 numpy:

    >>> import numpy as np
    >>> np.__version__
    '1.21.0.dev0+402.gc4ae3ce64'
    >>> 
    

    下一个:熊猫。

    更新: 经过一番搜索,我找到了this interesting article,它表明您可以轻松地以 Rosatta 模式启动终端。这也解决了问题。

    但是,我正在使用无头 Mac Mini,因此我仍然需要确定该解决方案在该特定设置中是否也可行。

    更新 2

    感谢this answer on SO,我现在也可以使用 pandas。

    【讨论】:

    • 我有同样的问题,虽然它的一个变种。我在 docker 中安装了 numpy(M1 的预览版)。这里的步骤有助于为我指明方向。我需要安装特定版本的 numpy,所以在克隆后我检查了我需要的版本 git checkout v1.xx.x 并继续安装。
    • 轻微变体:跳过 git 下载,我直接做了pip3 install --no-binary :all: --no-use-pep517 numpy,它对我有用
    • 对于Python 3.9.5pip 21.1.2,git-download 方法不起作用,但@CrepeGoat 建议的跳过方法效果很好!太好了。
    • 谢谢!!!单线是 pip install git+github.com/numpy/numpy.git --no-binary :all: --no-use-pep517
    【解决方案4】:

    首先,使用 python 3.8 版本的基于 m1 arm 的 Mac 不支持 numpy。解决此问题的方法是将您的 python 版本更新到 3.9。这是最新版本的python,可能有点不稳定。如果您想使用 tensorflow,请不要更新到 python 3.9 版本,因为它们不支持它,支持将提供 2.5 版(估计)。因此,如果您不想使用 tensorflow 并想通过 pip install 使用 numpy,那么请继续安装 python3.9 并将其设为您的默认 python 解释器。

    我会推荐你​​使用 Homebrew 来安装 python 3.9,因为它就像运行一个简单的命令一样简单。

    【讨论】:

    • 您能否添加指向支持您所说的文档的链接?
    • 是的,所以对于我的 tensorflow 响应,请关注这个线程 github.com/tensorflow/tensorflow/issues/44485 检查 numpy 的工作是巧合,因为我为我安装了一个包,然后我尝试安装 numpy 并且它工作。您当然可以通过从源代码下载并安装 numpy 来寻找其他无需轮子帮助的安装 numpy 的解决方案(应该可以,但我不确定)。
    【解决方案5】:

    在尝试了大量建议的方法后,我终于找到了一种方法,可以在带有 M1 芯片的新 macbook pro 上使用 numpy。

    对 M1 芯片使用 this docker preview

    例如这是一个成功安装numpy的Dockerfile。

    FROM python
    
    RUN python3 -m pip install numpy
    

    构建它:

    docker build -t numpytest:latest .
    

    然后运行它:

    docker run -it --rm numpytest:latest
    

    您可以验证 numpy 是否已安装并正常工作:

    Python 3.9.1 (default, Jan 12 2021, 13:13:57) 
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numpy as np
    >>> np.arange(15).reshape(3, 5)
    array([[ 0,  1,  2,  3,  4],
           [ 5,  6,  7,  8,  9],
           [10, 11, 12, 13, 14]])
    >>> 
    

    【讨论】:

      【解决方案6】:

      请注意,目前(2021 年 2 月)在 M1 ARM 架构上用于 python 的完整数据科学套件的唯一可靠构建环境是通过 miniforge。

      例如

      brew install --cask miniforge
      conda init zsh
      conda activate
      conda install numpy scipy scikit-learn
      

      【讨论】:

      • 谢谢,这是唯一对我有用的东西。我正在使用 VScode M1 内部人员构建并将我的解释器设置为 miniforge 的所有这些工作。
      【解决方案7】:

      对我有用的是运行 iTerm 并启用“使用 Rosetta 打开”选项并在安装 numpy 之前升级 pip。

      除了启用此选项之外,您还可以运行pip install 和 python 使用arch -x86_64 选择不同的架构。使用虚拟环境的示例:

      $ python3 -m venv ~/myenv
      $ source ~/myenv/bin/activate
      (myenv)$ python3 -m pip install --upgrade pip
      Collecting pip
        Using cached pip-21.0.1-py3-none-any.whl (1.5 MB)
      Installing collected packages: pip
        Attempting uninstall: pip
          Found existing installation: pip 20.2.3
          Uninstalling pip-20.2.3:
            Successfully uninstalled pip-20.2.3
      Successfully installed pip-21.0.1
      
      (myenv)$ arch -x86_64 pip install numpy
      Collecting numpy
        Using cached numpy-1.20.1-cp39-cp39-macosx_10_9_x86_64.whl (16.1 MB)
      Installing collected packages: numpy
      Successfully installed numpy-1.20.1
      
      (myenv)$ arch -x86_64 python3
      Python 3.9.1 (v3.9.1:1e5d33e9b9, Dec  7 2020, 12:44:01)
      [Clang 12.0.0 (clang-1200.0.32.27)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import numpy
      >>> numpy.__version__
      '1.20.1'
      

      【讨论】:

        【解决方案8】:

        我试图在没有 Rosetta 2 的情况下安装 numpy,但此处列出的解决方案对我来说失败了。布鲁挽救了这一天。我安装了它

        brew install numpy
        

        【讨论】:

        • 这对我也有用。以防万一,我通过brew 安装了python@3.9
        【解决方案9】:

        好吧,我猜它已在未发布的上游修复。撰写本文时最新的 1.20.2 的 pip 安装失败。但是我克隆了 git@github.com:numpy/numpy.git,然后在我的 venv 中执行了正常的“python setup.py install”(这是通过 Homebrew 安装的 Python 3.9.5),它似乎可以工作。还没有彻底测试过。

        【讨论】:

          【解决方案10】:

          针对 pipenv 用户的解决方案:

          git clone https://github.com/numpy/numpy.git --recursive
          cd numpy
          pip3 install build
          python3 -m build
          cd dist
          cp numpy-1.22.0.dev0+97.g4635fc852-cp39-cp39-macosx_11_0_arm64.whl ../../ # filename is current sample, next folder to your project directory
          

          添加到 Pipfile 中:

          [packages]
          numpy = { path = "numpy-1.22.0.dev0+97.g4635fc852-cp39-cp39-macosx_11_0_arm64.whl" }
          
          pipenv install
          

          然后你的 numpy 将被安装。

          【讨论】:

            【解决方案11】:

            CrepeGoat 的评论对我有用:

            pip3 install --no-binary :all: --no-use-pep517 numpy
            

            【讨论】:

              【解决方案12】:

              正如之前的回答中提到的,当我使用 Rosetta 打开终端时,安装很顺利。

              但是对于使用 Pycharm 终端的任何人,请执行以下操作以使用 Rosetta 运行终端。

              • 转到首选项 -> 工具 -> 终端
              • 将脚本路径更新为“env /usr/bin/arch -x86_64 /bin/zsh --login”

              我尝试了很多其他选项,但到目前为止这是我找到的最简单的解决方案。

              【讨论】:

                【解决方案13】:

                自 NumPy 1.21.0 以来,它已经发布了适用于 Mac 上 Python 3.8 和 Python 3.9 的 universal2 轮子。它可以安装在 Mac M1 上。

                我已经在我的 M1 上使用 Python 3.9.2、macOS Big Sur (11.5.1) 和 pip 21.1.3 对其进行了测试。只需使用pip/pip3 安装即可。

                发行说明:https://github.com/numpy/numpy/releases/tag/v1.21.0

                【讨论】:

                • 我的 M1 安装了 Python 3.8.9,但无法构建 numpy。通过 Homebrew 安装 Python 3.9.10 修复了它。
                【解决方案14】:

                在蒙特雷也面临同样的问题。

                将 pip 版本从 20.2.3 升级到 21.3.1 解决了这个问题。

                source env/bin/activate
                pip install -U pip
                pip install numpy
                

                【讨论】:

                  猜你喜欢
                  • 2021-04-10
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2021-11-26
                  • 2021-03-31
                  • 2021-04-15
                  • 1970-01-01
                  相关资源
                  最近更新 更多