如何在 M1 Mac 上本地运行 Python 3.9.1?

时间:2021-01-04 08:27:03

标签: python-3.9 apple-silicon

目前似乎不可能使用 Anaconda 和 Xcode 12。通过空闲,它通过 Rosetta 运行。似乎没有对此进行讨论,所以要么我很天真,要么这对其他人也有用。

Python 说:“从 3.9.1 开始,Python 现在完全支持在 macOS 11.0 (Big Sur) 和 Apple Silicon Macs(基于 ARM64 架构)上构建和运行。一个新的通用构建变体,universal2,现在是可在一组可执行文件中原生支持 ARM64 和 Intel 64"https://docs.python.org/3/whatsnew/3.9.html

请帮助新手弄清楚如何利用他最近的冲动购买。

4 个答案:

答案 0 :(得分:7)

您现在可以通过多种途径安装 Python 3.9.1,但目前(2021 年 2 月)在 M1 ARM 架构上为 Python 提供完整数据科学套件的最全面的构建环境是通过 miniforge。

例如

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

答案 1 :(得分:0)

我使用的是 python3.9.4。我只使用自制软件安装它。

我尝试通过 pip3 install pandas

安装 pandas

花了一段时间,但它已成功安装到我的 M1 Macbook Pro 中。

这是日志

❯ pip3 install pandas

Collecting pandas
  Downloading pandas-1.2.4.tar.gz (5.5 MB)
     |████████████████████████████████| 5.5 MB 855 kB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting numpy>=1.16.5
  Using cached numpy-1.20.2-cp39-cp39-macosx_11_0_arm64.whl
Collecting pytz>=2017.3
  Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
     |████████████████████████████████| 510 kB 8.8 MB/s
Collecting python-dateutil>=2.7.3
  Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
     |████████████████████████████████| 227 kB 10.5 MB/s
Requirement already satisfied: six>=1.5 in /opt/homebrew/lib/python3.9/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
Building wheels for collected packages: pandas
  Building wheel for pandas (PEP 517) ... /

done
  Created wheel for pandas: filename=pandas-1.2.4-cp39-cp39-macosx_11_0_arm64.whl size=9354006 sha256=87fead2b2cacdfdc448c444899dfffca3b82275635ac8d51a39790ede623e342
  Stored in directory: /Users/pks/Library/Caches/pip/wheels/1c/18/1d/96f6fb133a77724bc42fce621a44162d840d037b9289c4a874
Successfully built pandas
Installing collected packages: pytz, python-dateutil, numpy, pandas
Successfully installed numpy-1.20.2 pandas-1.2.4 python-dateutil-2.8.1 pytz-2021.1

答案 2 :(得分:0)

我升级到 3.9.4

  1. 下载 Python 通用安装程序 - https://www.python.org/downloads/mac-osx/

注意:我仍然无法安装 sudo pip install mysqlclient。
我已经添加到

  1. 更新自制软件 - 参见https://brew.sh
  2. 将 /opt/homebrew/bin 添加到 .bash_profile 中的 PATH(不要忘记源 .bash_profile)

答案 3 :(得分:0)

您现在可以在 Mac M1(Apple Silicon)上本地安装 Python 3.9.4。我正在使用 pyenv 安装所有原生 ARM 的 Python 3.7、3.8 和 3.9。例如,要安装 3.9.4:

$ pyenv install 3.9.4
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.4.tar.xz...
-> https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tar.xz
Installing Python-3.9.4...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.4 to /Users/squademy/.pyenv/versions/3.9.4

有关安装 pyenv 和多个 Python 版本的完整指南,您可以阅读这篇文章:https://squademy.medium.com/install-python-on-macos-11-m1-apple-silicon-using-pyenv-12e0729427a9