使用brew包管理工具来安装Python3
WangHai@WangHai-MacBook-Pro ~ python ✔ 659 11:16:40
Python 2.7.16 (default, Jan 27 2020, 04:46:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> ^D
WangHai@WangHai-MacBook-Pro ~ brew install python3 ✔ 660 11:24:49
Error: The following formula
python
cannot be installed as binary package and must be built from source.
Install the Command Line Tools:
xcode-select --install
出现错误提示:需要安装xcode命令行工具
安装xcode命令行工具
WangHai@WangHai-MacBook-Pro ~ brew install python3 ✔ 662 11:29:28
==> Installing dependencies for python: gdbm, readline, sqlite and xz
==> Installing python dependency: gdbm
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1.mojave.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring gdbm-1.18.1.mojave.bottle.1.tar.gz
🍺 /usr/local/Cellar/gdbm/1.18.1: 20 files, 586.8KB
==> Installing python dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.1.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/3c754391e9d243835811d128771ca0f1a565024100fd2c2871534353d46aa
######################################################################## 100.0%
==> Pouring readline-8.0.1.mojave.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
For compilers to find readline you may need to set:
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
==> Summary
🍺 /usr/local/Cellar/readline/8.0.1: 48 files, 1.5MB
==> Installing python dependency: sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.31.1.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/db7e3a6498bfdb4b4ceb8e8416020e2ad70de14975437f2e2a027485daeb2
######################################################################## 100.0%
==> Pouring sqlite-3.31.1.mojave.bottle.tar.gz
==> Caveats
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.
If you need to have sqlite first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.zshrc
For compilers to find sqlite you may need to set:
export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"
==> Summary
🍺 /usr/local/Cellar/sqlite/3.31.1: 11 files, 4MB
==> Installing python dependency: xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.4.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/010667293df282c8bceede3bcd36953dd57c56cef608d09a5b50694ab7d4b
######################################################################## 100.0%
==> Pouring xz-5.2.4.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/xz/5.2.4: 92 files, 1MB
==> Installing python
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.6_1.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/643d627c2b4fc03a3286c397d299284ef8ce2d4a832737e41175f297d4f08
######################################################################## 100.0%
==> Pouring python-3.7.6_1.mojave.bottle.tar.gz
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/
==> Caveats
Python has been installed as
/usr/local/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/libexec/bin
You can install Python packages with
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
==> Summary
🍺 /usr/local/Cellar/python/3.7.6_1: 3,977 files, 60.8MB
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/WangHai/Library/Caches/Homebrew/cmake--3.16.4.high_sierra.bottle.tar.gz... (16.3MB)
Removing: /Users/WangHai/Library/Caches/Homebrew/openssl@1.1--1.1.1d.high_sierra.bottle.tar.gz... (5.2MB)
Removing: /Users/WangHai/Library/Caches/Homebrew/protobuf--3.11.4.high_sierra.bottle.tar.gz... (4.9MB)
Removing: /Users/WangHai/Library/Caches/Homebrew/.DS_Store... (6KB)
Removing: /Users/WangHai/Library/Caches/Homebrew/portable-ruby-2.6.3.mavericks.bottle.tar.gz... (9.0MB)
Removing: /Users/WangHai/Library/Caches/Homebrew/mysql--8.0.19.high_sierra.bottle.2.tar.gz... (80.4MB)
Removing: /Users/WangHai/Library/Caches/Homebrew/mysql-boost-8.0.19.tar.gz... (251.9MB)
Removing: /Users/WangHai/Library/Logs/Homebrew/cmake... (64B)
Removing: /Users/WangHai/Library/Logs/Homebrew/mysql... (792B)
Removing: /Users/WangHai/Library/Logs/Homebrew/openssl@1.1... (64B)
Removing: /Users/WangHai/Library/Logs/Homebrew/protobuf... (64B)
Pruned 3 symbolic links and 2 directories from /usr/local
==> Caveats
==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
For compilers to find readline you may need to set:
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
==> sqlite
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.
If you need to have sqlite first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.zshrc
For compilers to find sqlite you may need to set:
export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"
==> python
Python has been installed as
/usr/local/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/libexec/bin
You can install Python packages with
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
WangHai@WangHai-MacBook-Pro
此时已经安装完成了,我们通过python3命令来使用python
WangHai@WangHai-MacBook-Pro ~ python3 ✔ 662 11:46:25
Python 3.7.6 (default, Dec 30 2019, 19:38:28)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>