Brew 安装
- 搜索可以安装的包
brew search python
==> Formulae
app-engine-python bpython micropython python-markdown python-yq python@3.9 ✔ pythran
boost-python gst-python ptpython python-tabulate python@3.7 reorder-python-imports jython
boost-python3 ipython python-launcher python-tk@3.9 python@3.8 ✔ wxpython cython
==> Casks
homebrew/cask/awips-python homebrew/cask/mysql-connector-python
- 安装
# 这里我安装了3.7, 没有选择3.8, 担心有些组件包对3.8支持不好
brew install python@3.7
==> Caveats
Python has been installed as
/usr/local/opt/python@3.7/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python@3.7/libexec/bin
You can install Python packages with
/usr/local/opt/python@3.7/bin/pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
python@3.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have python@3.7 first in your PATH, run:
echo 'export PATH="/usr/local/opt/python@3.7/bin:$PATH"' >> ~/.zshrc
For compilers to find python@3.7 you may need to set:
export LDFLAGS="-L/usr/local/opt/python@3.7/lib"
For pkg-config to find python@3.7 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/python@3.7/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/python@3.7/3.7.11: 4,619 files, 71.6MB
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /usr/local/Cellar/apr/1.7.0... (59 files, 1.4MB)
Removing: /usr/local/Cellar/autoconf/2.69... (70 files, 3.0MB)
Removing: /usr/local/Cellar/c-ares/1.16.0... (74 files, 530.3KB)
Removing: /usr/local/Cellar/curl/7.69.1... (457 files, 3.4MB)
Removing: /usr/local/Cellar/freetds/1.1.32... (66 files, 3.6MB)
Removing: /usr/local/Cellar/freetype/2.10.1... (61 files, 2.2MB)
Removing: /usr/local/Cellar/gdbm/1.18.1... (20 files, 602.8KB)
Removing: /usr/local/Cellar/gmp/6.2.0... (20 files, 3.2MB)
Removing: /usr/local/Cellar/icu4c/64.2... (257 files, 69.3MB)
Removing: /usr/local/Cellar/krb5/1.18... (162 files, 4MB)
Removing: /Users/haolin/Library/Caches/Homebrew/libevent--2.1.12... (681.3KB)
Removing: /usr/local/Cellar/libffi/3.2.1... (16 files, 296.9KB)
Removing: /usr/local/Cellar/libidn2/2.0.5... (68 files, 668.8KB)
Removing: /usr/local/Cellar/libpq/12.2_1... (2,240 files, 23.8MB)
Removing: /usr/local/Cellar/libtiff/4.1.0... (247 files, 3.7MB)
Removing: /usr/local/Cellar/libtool/2.4.6_1... (70 files, 3.7MB)
Removing: /usr/local/Cellar/libzip/1.6.1... (135 files, 598.5KB)
Removing: /usr/local/Cellar/m4/1.4.18... (13 files, 621.6KB)
Removing: /Users/haolin/Library/Caches/Homebrew/ncurses--6.2... (2.3MB)
Removing: /usr/local/Cellar/nghttp2/1.40.0... (26 files, 2.7MB)
Removing: /usr/local/Cellar/openldap/2.4.49... (328 files, 6.7MB)
Removing: /Users/haolin/Library/Caches/Homebrew/openssl@1.1--1.1.1k... (5.4MB)
Removing: /usr/local/Cellar/readline/8.0.4... (48 files, 1.5MB)
Removing: /usr/local/Cellar/sqlite/3.31.1... (11 files, 4MB)
Removing: /usr/local/Cellar/tidy-html5/5.6.0... (14 files, 2.6MB)
Removing: /Users/haolin/Library/Caches/Homebrew/tmux--3.2a... (430.3KB)
Removing: /usr/local/Cellar/unixodbc/2.3.7... (46 files, 1.9MB)
Removing: /Users/haolin/Library/Caches/Homebrew/utf8proc--2.6.1... (173KB)
Removing: /usr/local/Cellar/webp/1.1.0... (39 files, 2.1MB)
Removing: /Users/haolin/Library/Caches/Homebrew/openssl@1.1_bottle_manifest--1.1.1k... (6KB)
Removing: /Users/haolin/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz... (9.1MB)
Removing: /Users/haolin/Library/Caches/Homebrew/tmux_bottle_manifest--3.2a... (6.8KB)
Removing: /Users/haolin/Library/Caches/Homebrew/ncurses_bottle_manifest--6.2... (7.3KB)
Removing: /Users/haolin/Library/Caches/Homebrew/libevent_bottle_manifest--2.1.12... (6.9KB)
Removing: /Users/haolin/Library/Caches/Homebrew/utf8proc_bottle_manifest--2.6.1... (5.3KB)
Pruned 1 symbolic links and 8 directories from /usr/local
总结下
安装目录: /usr/local/opt/python@3.7/bin/python3
命令工具目录: /usr/local/opt/python@3.7/libexec/bin
包安装命令: /usr/local/opt/python@3.7/bin/pip3 install
包安装目录: /usr/local/lib/python3.7/site-packages
- 链接 python3
因为 Macos 系统默认自带的是 python 2.7, 需要将修改系统 PATH 变量, 改为默认使用 python3
# 导入 python3 命令路径
echo 'export PATH="/usr/local/opt/python@3.7/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/python@3.7/lib"
export PKG_CONFIG_PATH="/usr/local/opt/python@3.7/lib/pkgconfig"
# 加载配置
source ~/.zshrc
# 测试
python3 --version
Python 3.7.11