如何在 M1 (Apple Silicon/Darwin-arm64) 上安装和导入 Scipy、Numpy、NumExpr 等? [英] How to install and import Scipy, Numpy, NumExpr and others on M1 (Apple Silicon / Darwin-arm64)?
问题描述
我有一个 Apple 的 M1 处理器,它是一种新的 ARM64 架构,并且为许多数据科学 Python 包提供的二进制文件不会在其上运行,并且在大多数情况下编译它们会失败.
I have an M1 processor from Apple, which is a new ARM64 architecture, and the binaries provided for many data science Python packages will not run on it, and compiling them fails in most cases.
诸如如何在 Apple Silicon 上安装 SciPy 等问题(ARM/M1) 或 numpy 构建在 M1 中失败Big sur 11.1 提供了许多不同的答案,其中一些有效,大多数无效.但是,即使对于那些设法使模块编译的人,我也不明白如何让 pip
安装我本地编译的包,而不是从 pypy 获取它们(并且失败).
Questions such as How to install SciPy on Apple Silicon (ARM / M1) or numpy build fail in M1 Big sur 11.1 offer many different answers, some of which work and most don't. However, even for those that manage to make the modules compile, I don't understand how I can make pip
install my locally compiled packages instead of fetching them (and failing) from pypy.
如何将 numpy
、scipy
、numexpr
和其他软件安装为具有 M1 处理器的计算机的依赖项?
How can I install numpy
, scipy
, numexpr
and others as a dependency on a computer with an M1 processor?
推荐答案
- 使用 Homebrew 安装 Miniforge 以在本地编译这些模块:
brew install miniforge
.莉> - 使用
conda
而不是pip
安装您需要的模块:conda install numpy
(和scipy
、numexpr
...). - 在您安装依赖项的环境(全局、用户或带有
venv
、pew
或类似的环境)中,像往常一样安装,但让您的包管理器知道通过定义来加载您之前安装的这些本机模块PYTHONPATH
:在安装命令前加上PYTHONPATH=/opt/homebrew/Caskroom/miniforge/base/pkgs/:$PYTHONPATH
.例如:PYTHONPATH=/opt/homebrew/Caskroom/miniforge/base/pkgs/:$PYTHONPATH pip3 install
.
- Install Miniforge with Homebrew to compile these modules locally:
brew install miniforge
. - Install the modules you need with
conda
instead ofpip
:conda install numpy
(andscipy
,numexpr
…). - In the environment in which you install your dependencies (global, user or virtual environment with
venv
,pew
or similar), install as you would usually, but let your package manager know to load these native modules you installed earlier by definingPYTHONPATH
: prefix the install command withPYTHONPATH=/opt/homebrew/Caskroom/miniforge/base/pkgs/:$PYTHONPATH
. For example:PYTHONPATH=/opt/homebrew/Caskroom/miniforge/base/pkgs/:$PYTHONPATH pip3 install
.
这篇关于如何在 M1 (Apple Silicon/Darwin-arm64) 上安装和导入 Scipy、Numpy、NumExpr 等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!