简体   繁体   English

如何在 M1 mac 上使用 pandas? (没有rosetta或以任何其他方式更改为x86环境)

[英]How to use pandas on M1 mac? (without rosetta or changing to x86 environment in any other way)

Last I wrote a python project was less than 2 months ago and everything worked fine.上次我在不到 2 个月前写了一个 python 项目,一切正常。 I'm not sure if while working on other project I messed something up on my mac but now when trying to run python files which used to run perfectly, the following error appears:我不确定在处理其他项目时是否在我的 Mac 上搞砸了一些东西,但现在当尝试运行曾经完美运行的 python 文件时,会出现以下错误:

dlopen(/opt/homebrew/lib/python3.9/site-packages/pandas/_libs/interval.cpython-39-darwin.so, 0x0002): tried: '/opt/homebrew/lib/python3.9/site-packages/pandas/_libs/interval.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/interval.cpython-39-darwin.so' (no such file), '/usr/lib/interval.cpython-39-darwin.so' (no such file)

I understand there is an issue with the architecture x86 vs arm so I tried seeing what platform the terminal is on with:我了解 x86 与 arm 架构存在问题,因此我尝试查看终端使用的平台:

python -c 'import platform; print(platform.platform())'  

which confirmed it was arm64.确认它是arm64。 Doing some googling and looking at similar issues such as Trouble installing Pandas on new MacBook Air M1 it seems like it would be possible to run the python project in an x86 environment, however like already mentioned, it worked fine before, and it seems there was no update since, so what could have happened that pandas (and perhaps other libs) no longer work on arm, and how can it be reverted?进行一些谷歌搜索并查看类似的问题,例如在新的 MacBook Air M1 上安装 Pandas 时遇到问题,似乎可以在 x86 环境中运行 python 项目,并且之前已经提到过它的环境很好,但它似乎已经很好了此后没有更新,所以 pandas(可能还有其他库)不再适用于 arm 会发生什么情况,如何恢复?

You should try using miniforge .您应该尝试使用miniforge

its definition from its GitHub repository:其 GitHub 存储库中的定义:

This repository holds a minimal installer for Conda specific to conda-forge.此存储库包含特定于 conda-forge 的最小 Conda 安装程序。 Miniforge allows you to install the conda package manager with the following features pre-configured: Miniforge 允许您安装 conda package 管理器,并预先配置了以下功能:

Its main feature that will be useful for us它的主要功能对我们有用

An emphasis on supporting various CPU architectures (x86_64, ppc64le, and aarch64 including Apple M1).强调支持各种 CPU 架构(x86_64、ppc64le 和 aarch64,包括 Apple M1)。

The Process I use:我使用的过程:

  1. Create a conda environment and usually go with "python3.9".创建一个 conda 环境,通常使用“python3.9”创建 go。
  2. Install the packages from the conda, most of them are available but some are not.从 conda 安装软件包,其中大部分可用,但有些不可用。
  3. After trying and installing all the packages possible with miniforge, I use PIP for the remaining packages.在尝试使用 miniforge 安装所有可能的软件包后,我将PIP用于剩余的软件包。

This workflow has worked pretty well for me and hope it helps you.这个工作流程对我来说效果很好,希望对你有所帮助。 I want to utilize the native m1 performance and I think you will be able to see the difference.我想利用原生的 m1 性能,我认为您将能够看到差异。

By default, miniforge only downloads arm compatible builds of python packages.默认情况下,miniforge 只下载与 arm 兼容的 python 包的构建。 till now I have not faced any major issue working with most data science libraries, except with PyTorch.到目前为止,除了 PyTorch 之外,我在使用大多数数据科学库时还没有遇到任何重大问题。

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

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