简体   繁体   English

M1 Mac 原生安装Python3.7 Numpy

[英]Install Python3.7 with Numpy natively on M1 Mac

I need to Install Python3.7 to support Spark 2 on an M1 Mac.我需要在 M1 Mac 上安装 Python3.7 以支持 Spark 2。

I can get Python3.7 installed using pyenv, but when I try to install any of the data science libs, like numpy, I get failure: ModuleNotFoundError: No module named '_ctypes'我可以使用 pyenv 安装 Python3.7,但是当我尝试安装任何数据科学库时,比如 numpy,我会失败: ModuleNotFoundError: No module named '_ctypes'

This seems to be related to libffi.这似乎与 libffi 有关。 Looking through the build logs for pyenv, I'm seeing this error:查看 pyenv 的构建日志,我看到了这个错误:

.../Python-3.7.10/Modules/_ctypes/libffi_osx/include/fficonfig.h:51:2: error: "Unknown CPU type"
#error "Unknown CPU type"
 ^
1 error generated.

Python build finished successfully!
Failed to build these modules:
_ctypes               _decimal

Has anyone been able to successfully install 3.7 with numpy natively?有没有人能够在本地成功安装 numpy 的 3.7? I'm not looking for answers that involve Rosetta.我不是在寻找涉及 Rosetta 的答案。

Use miniconda to install things: see this post .使用miniconda安装东西:见这篇文章

Miniconda is an open source version of the conda package/environment manager, as an alternative to pyenv + brew. Miniconda 是 conda 包/环境管理器的开源版本,作为 pyenv + brew 的替代品。

It will install ARM native versions of python by default, as well as native versions of modules.它将默认安装 ARM 本机版本的 python 以及本机版本的模块。 This definitely include ARM native numpy.这绝对包括 ARM 原生 numpy。

I've quite sucessfully installed native python 3.7-3.10 and native numpy without any problems at all.我已经非常成功地安装了本机 python 3.7-3.10 和本机 numpy 没有任何问题。 (In fact ARM native versions of almost every package I use). (事实上,我使用的几乎所有 package 的原生版本都是 ARM 原生版本)。

With conda you use conda to install packages, not pip.使用 conda,您可以使用 conda 安装软件包,而不是 pip。

So to install numpy you do conda install numpy in the environment you're in.因此,要安装 numpy,请在您所在的环境中执行conda install numpy

I had the same issue and the way I could fix it was to first create a conda environment with a new python version and then change the python version inside the activated environment with:我有同样的问题,我可以解决它的方法是首先使用新的 python 版本创建一个 conda 环境,然后在激活的环境中更改 python 版本:

conda install -c conda-forge python=3.7.8

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

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