1 mac安装python3.9 arm64版之后,通过pip3安装numpy、pandas及matplotlib等包时,会出现错误。原因有很多文章可以参考不再赘述。下面介绍一种可以成功安装这些包的方法。

首先安装miniforge,他可以理解成是默认使用conda forge这个channel的miniconda,由github上一个团队负责维护,有点是包版本较新,最大的优点是支持arm mac!

点击以下链接下载arm64版本的miniforge:

https://github.com/conda-forge/miniforge/#download 

或者通过brew 进行安装、通过brew默认安装的版本即为arm64版

brew install miniforge

注意,arm64版本的miniforge的基础环境是python3.9

在终端中打开下载文件所在目录

bash Miniforge3-MacOSX-arm64.sh

按照指示完成安装。(注意安装完成后会问你是否将conda的base环境设为终端打开的默认环境,不需要的话回复no,但是目前推荐yes,因为conda下的python环境比目前系统自带的更完善,且安装各种包的限制少)

接下来通过conda新建虚拟环境,安装numpy、pandas和matplotlib:

 

  1. 可以在创建虚拟环境的时候就安装所需的包
conda create -n py39t numpy matplotlib pandas python=3.9

 

2.也可以先创建虚拟环境再一一install

conda create -n py39t python=3.9
conda install -n py39t numpy
conda install -n py39t matplotlib
conda install -n py39t pandas

3.完成,换一个终端打开:

#换到刚创建的py39t环境下
conda activate py39t 
#查看已安装的包
(py39t) ca ~ % pip3 list
Package         Version
--------------- -------------------
certifi         2020.12.5
cycler          0.10.0
kiwisolver      1.3.1
matplotlib      3.3.4
numpy           1.20.1
olefile         0.46
pandas          1.2.2
Pillow          8.1.0
pip             21.0.1
pyparsing       2.4.7
python-dateutil 2.8.1
pytz            2021.1
setuptools      49.6.0.post20210108
six             1.15.0
tornado         6.1
wheel           0.36.2

 

参考来源:

M1 Mac 安装numpy和pandas

发表了文章02-23

Mac(m1)下镜像飞速安装Homebrew教程

Carl
四大皆空
 
 

输入以下代码:

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"

不用官方的,新Mac弃用ruby改为bash

% /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/bin
/opt/homebrew/etc
/opt/homebrew/include
/opt/homebrew/lib
/opt/homebrew/sbin
/opt/homebrew/share
/opt/homebrew/var
/opt/homebrew/opt
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/var/homebrew
/opt/homebrew/var/homebrew/linked
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew
==> /usr/bin/sudo /usr/sbin/chown root:wheel /opt/homebrew
==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
==> /usr/bin/sudo /bin/chmod g+rwx /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
==> /usr/bin/sudo /usr/sbin/chown carl /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
==> /usr/bin/sudo /usr/sbin/chown -R carl:admin /opt/homebrew
==> /usr/bin/sudo /bin/mkdir -p /Users/carl/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/carl/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown -R carl /Users/carl/Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 175016, done.
remote: Counting objects: 100% (175016/175016), done.
remote: Compressing objects: 100% (40688/40688), done.
remote: Total 175016 (delta 130389), reused 174895 (delta 130342)
Receiving objects: 100% (175016/175016), 44.62 MiB | 8.24 MiB/s, done.
Resolving deltas: 100% (130389/130389), done.
From https://mirrors.ustc.edu.cn/brew
 * [new branch]      master     -> origin/master
 
 * [new tag]             3.0.2      -> 3.0.2
remote: Enumerating objects: 7531, done.
remote: Counting objects: 100% (7531/7531), done.
remote: Compressing objects: 100% (1581/1581), done.
remote: Total 7531 (delta 5798), reused 7531 (delta 5798)
Receiving objects: 100% (7531/7531), 1.61 MiB | 6.74 MiB/s, done.
Resolving deltas: 100% (5798/5798), completed with 737 local objects.
From https://mirrors.ustc.edu.cn/brew
 * [new tag]             1.1.0.1              -> 1.1.0.1
 * [new tag]             1.1.2.1              -> 1.1.2.1
 * [new tag]             1.2.7                -> 1.2.7
 * [new tag]             1.2.8                -> 1.2.8
 * [new tag]             backup/activesupport-23-38-09 -> backup/activesupport-23-38-09
 * [new tag]             backup/brew-cask-style-14-54-55 -> backup/brew-cask-style-14-54-55
 * [new tag]             backup/create-cache-00-29-47 -> backup/create-cache-00-29-47
 * [new tag]             backup/days-03-02-52 -> backup/days-03-02-52
 * [new tag]             backup/days-03-02-59 -> backup/days-03-02-59
 * [new tag]             backup/days-19-30-23 -> backup/days-19-30-23
 * [new tag]             backup/gpg-verification-01-53-16 -> backup/gpg-verification-01-53-16
 * [new tag]             backup/remove-popen-read-19-56-50 -> backup/remove-popen-read-19-56-50
 * [new tag]             backup/remove-popen-read-20-00-21 -> backup/remove-popen-read-20-00-21
HEAD is now at 787e6cb75 Merge pull request #10667 from dtrodrigues/pr-man
==> Tapping homebrew/core
remote: Enumerating objects: 915097, done.
remote: Total 915097 (delta 0), reused 0 (delta 0)B | 8.79 MiB/s 
Receiving objects: 100% (915097/915097), 358.19 MiB | 8.78 MiB/s, done.
Resolving deltas: 100% (626173/626173), done.
From https://mirrors.ustc.edu.cn/homebrew-core
 * [new branch]      master     -> origin/master
HEAD is now at ff20a31ae0 gh: update 1.6.2 bottle.
Warning: /opt/homebrew/bin is not in your PATH.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this `install` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Add Homebrew to your PATH in /Users/carl/.zprofile:
    echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/ca/.zprofile
    eval $(/opt/homebrew/bin/brew shellenv)
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh
ca@CadeMacBook- homebrew 

最后看到==> Installation successful!就说明安装成功了。

但执行brew -v 不显示版本号

% brew -v
zsh: command not found: brew

需更改系统环境变量,将/opt/homebrew/bin加入$PATH

由于新Mac默认shell为zsh,配置文件为:.zshrc

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home"
CLASS_PATH="$JAVA_HOME/lib"
BREW_HOME='/opt/homebrew'
M2_HOME=/Users/Documents/maven/apache-maven-3.6.3
PATH="$JAVA_HOME/bin":"$M2_HOME/bin":"$BREW_HOME/bin":$PATH
export JAVA_HOME
export BREW_HOME
export M2_HOME
export CLASS_PATH
export PATH

验证:

% brew -v
Homebrew 3.0.2
Homebrew/homebrew-core (git revision ff20a; last commit 2021-02-23)

% brew help 
Example usage:
  brew search [TEXT|/REGEX/]
  brew info [FORMULA...]
  brew install FORMULA...
  brew update
  brew upgrade [FORMULA...]
  brew uninstall FORMULA...
  brew list [FORMULA...]

Troubleshooting:
  brew config
  brew doctor
  brew install --verbose --debug FORMULA

Contributing:
  brew create [URL [--no-fetch]]
  brew edit [FORMULA...]

Further help:
  brew commands
  brew help [COMMAND]
  man brew
  https://docs.brew.sh

// 啰嗦模式查看更新进度
brew update --verbose 

删除brew使用代码:

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
conda remove -n your_env_name(虚拟环境名称) --all
conda remove --name your_env_name  package_name  # 删除环境中的某个包

 

 

相关文章:

司徒正美:mac下镜像飞速安装Homebrew教程

MacOS 开发者必备 brew 使用详解

ineo6:mac下镜像飞速安装Homebrew教程

王加加:macOS Homebrew使用国内源

posted on 2021-10-23 21:51  Carl_99  阅读(1384)  评论(0编辑  收藏  举报