MacOS默认是python的版本是2.7,采用home-brew包管理工具去安装python3。
安装过程如下:
➜ ~ brew install python3
Updating Homebrew...
==> Installing dependencies for python: gdbm, sqlite and xz
==> Installing python dependency: gdbm
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1.catalina.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring gdbm-1.18.1.catalina.bottle.1.tar.gz
🍺 /usr/local/Cellar/gdbm/1.18.1: 20 files, 602.8KB
==> Installing python dependency: sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.30.1.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/38c39121f7634ec563bb201b483f66cf567dfe
-=O=- # # # #
curl: (35) LibreSSL SSL_connect: SSL_ERROR_ZERO_RETURN in connection to d29vzk4ow07wi7.cloudfront.net:443
Error: Failed to download resource "sqlite"
Download failed: https://homebrew.bintray.com/bottles/sqlite-3.30.1.catalina.bottle.tar.gz
Warning: Bottle installation failed: building from source.
==> Downloading https://sqlite.org/2019/sqlite-autoconf-3300100.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/sqlite/3.30.1 --enable-dynamic-extensions --enable-rea
==> make install
==> 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.30.1: 11 files, 3.9MB, built in 4 minutes 43 seconds
==> Installing python dependency: xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.4.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/5aa90b77d5e772dacd38146bbb7ff2fa43f210
######################################################################## 100.0%
==> Pouring xz-5.2.4.catalina.bottle.tar.gz
🍺 /usr/local/Cellar/xz/5.2.4: 92 files, 1MB
==> Installing python
Warning: Building python from source:
The bottle needs the Apple Command Line Tools to be installed.
You can install them, if desired, with:
xcode-select --install
==> Downloading https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tar.xz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/python/3.7.5 --enable-ipv6 --datarootdir=/usr/local/Cellar/
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python/3.7.5
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python/3.7.5/share/python
==> Downloading https://files.pythonhosted.org/packages/11/0a/7f13ef5cd932a107cd4c0f3ebc9d831d9b78e1a0
######################################################################## 100.0%
==> Downloading https://files.pythonhosted.org/packages/ce/ea/9b445176a65ae4ba22dce1d93e4b5fe182f953df
######################################################################## 100.0%
==> Downloading https://files.pythonhosted.org/packages/59/b0/11710a598e1e148fb7cbf9220fd2a0b82c98e94e
######################################################################## 100.0%
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
最后发现报错了,看提示是在执行brew link的时候没有权限。我们到/usr/local目录下看一下
➜ local git:(master) ✗ pwd
/usr/local
➜ local git:(master) ✗ ls -la
total 72
drwxr-xr-x 27 root wheel 864 4 22 10:11 .
drwxr-xr-x@ 11 root wheel 352 4 22 10:05 ..
-rw-r--r-- 1 zhongyili admin 0 4 4 2019 .com.apple.installer.keep
drwxr-xr-x 16 zhongyili admin 512 9 21 15:29 .git
drwxrwxr-x 5 zhongyili admin 160 10 23 2018 .github
-rw-r--r-- 1 zhongyili admin 1277 6 20 2017 .gitignore
-rw-r--r-- 1 zhongyili admin 1279 6 20 2017 .travis.yml
-rw-r--r-- 1 zhongyili admin 291 6 20 2017 .yardopts
-rw-r--r-- 1 zhongyili admin 98 6 20 2017 CHANGELOG.md
-rw-r--r-- 1 zhongyili admin 3161 6 20 2017 CODEOFCONDUCT.md
-rw-r--r-- 1 zhongyili admin 718 6 20 2017 CONTRIBUTING.md
drwxrwxr-x 24 zhongyili admin 768 9 21 15:14 Cellar
drwxrwxr-x 19 zhongyili admin 608 9 21 15:23 Homebrew
-rw-r--r-- 1 zhongyili admin 1334 6 20 2017 LICENSE.txt
drwxrwxr-x 5 zhongyili admin 160 10 23 2018 Library
-rw-r--r-- 1 zhongyili admin 6137 6 20 2017 README.md
drwxrwxr-x 81 zhongyili admin 2592 9 21 15:24 bin
drwxr-xr-x 4 zhongyili admin 128 10 23 2018 completions
drwxr-xr-x 48 zhongyili admin 1536 10 23 2018 docs
drwxrwxr-x 6 zhongyili admin 192 11 14 2019 etc
drwxrwxr-x 23 zhongyili admin 736 9 21 15:12 include
drwxrwxr-x 66 zhongyili admin 2112 9 21 15:12 lib
drwxr-xr-x 4 zhongyili admin 128 10 23 2018 manpages
drwxrwxr-x 36 zhongyili admin 1152 9 21 15:26 opt
drwxr-xr-x 3 zhongyili admin 96 10 23 2018 remotedesktop
drwxrwxr-x 11 zhongyili admin 352 9 21 15:06 share
drwxr-xr-x 3 zhongyili admin 96 10 23 2018 var
发现没有Frameworks目录,先建目录
➜ ~ sudo mkdir /usr/local/Frameworks
Password:
再看一下目录内容
➜ local git:(master) ✗ ls -la
total 72
drwxr-xr-x 28 root wheel 896 9 21 15:33 .
drwxr-xr-x@ 11 root wheel 352 4 22 10:05 ..
-rw-r--r-- 1 zhongyili admin 0 4 4 2019 .com.apple.installer.keep
drwxr-xr-x 16 zhongyili admin 512 9 21 15:32 .git
drwxrwxr-x 5 zhongyili admin 160 10 23 2018 .github
-rw-r--r-- 1 zhongyili admin 1277 6 20 2017 .gitignore
-rw-r--r-- 1 zhongyili admin 1279 6 20 2017 .travis.yml
-rw-r--r-- 1 zhongyili admin 291 6 20 2017 .yardopts
-rw-r--r-- 1 zhongyili admin 98 6 20 2017 CHANGELOG.md
-rw-r--r-- 1 zhongyili admin 3161 6 20 2017 CODEOFCONDUCT.md
-rw-r--r-- 1 zhongyili admin 718 6 20 2017 CONTRIBUTING.md
drwxrwxr-x 24 zhongyili admin 768 9 21 15:14 Cellar
drwxr-xr-x 2 root wheel 64 9 21 15:33 Frameworks
drwxrwxr-x 19 zhongyili admin 608 9 21 15:23 Homebrew
-rw-r--r-- 1 zhongyili admin 1334 6 20 2017 LICENSE.txt
drwxrwxr-x 5 zhongyili admin 160 10 23 2018 Library
-rw-r--r-- 1 zhongyili admin 6137 6 20 2017 README.md
drwxrwxr-x 81 zhongyili admin 2592 9 21 15:24 bin
drwxr-xr-x 4 zhongyili admin 128 10 23 2018 completions
drwxr-xr-x 48 zhongyili admin 1536 10 23 2018 docs
drwxrwxr-x 6 zhongyili admin 192 11 14 2019 etc
drwxrwxr-x 23 zhongyili admin 736 9 21 15:12 include
drwxrwxr-x 66 zhongyili admin 2112 9 21 15:12 lib
drwxr-xr-x 4 zhongyili admin 128 10 23 2018 manpages
drwxrwxr-x 36 zhongyili admin 1152 9 21 15:26 opt
drwxr-xr-x 3 zhongyili admin 96 10 23 2018 remotedesktop
drwxrwxr-x 11 zhongyili admin 352 9 21 15:06 share
drwxr-xr-x 3 zhongyili admin 96 10 23 2018 var
发现有Frameworks目录了,可是目录拥有者是root,我们修改一下拥有者
➜ local git:(master) ✗ sudo chown -R $(whoami) /usr/local/Frameworks
Password:
➜ local git:(master) ✗ ls -la
total 72
drwxr-xr-x 28 root wheel 896 9 21 15:33 .
drwxr-xr-x@ 11 root wheel 352 4 22 10:05 ..
-rw-r--r-- 1 zhongyili admin 0 4 4 2019 .com.apple.installer.keep
drwxr-xr-x 16 zhongyili admin 512 9 21 15:34 .git
drwxrwxr-x 5 zhongyili admin 160 10 23 2018 .github
-rw-r--r-- 1 zhongyili admin 1277 6 20 2017 .gitignore
-rw-r--r-- 1 zhongyili admin 1279 6 20 2017 .travis.yml
-rw-r--r-- 1 zhongyili admin 291 6 20 2017 .yardopts
-rw-r--r-- 1 zhongyili admin 98 6 20 2017 CHANGELOG.md
-rw-r--r-- 1 zhongyili admin 3161 6 20 2017 CODEOFCONDUCT.md
-rw-r--r-- 1 zhongyili admin 718 6 20 2017 CONTRIBUTING.md
drwxrwxr-x 24 zhongyili admin 768 9 21 15:14 Cellar
drwxr-xr-x 2 zhongyili wheel 64 9 21 15:33 Frameworks
drwxrwxr-x 19 zhongyili admin 608 9 21 15:23 Homebrew
-rw-r--r-- 1 zhongyili admin 1334 6 20 2017 LICENSE.txt
drwxrwxr-x 5 zhongyili admin 160 10 23 2018 Library
-rw-r--r-- 1 zhongyili admin 6137 6 20 2017 README.md
drwxrwxr-x 81 zhongyili admin 2592 9 21 15:24 bin
drwxr-xr-x 4 zhongyili admin 128 10 23 2018 completions
drwxr-xr-x 48 zhongyili admin 1536 10 23 2018 docs
drwxrwxr-x 6 zhongyili admin 192 11 14 2019 etc
drwxrwxr-x 23 zhongyili admin 736 9 21 15:12 include
drwxrwxr-x 66 zhongyili admin 2112 9 21 15:12 lib
drwxr-xr-x 4 zhongyili admin 128 10 23 2018 manpages
drwxrwxr-x 36 zhongyili admin 1152 9 21 15:26 opt
drwxr-xr-x 3 zhongyili admin 96 10 23 2018 remotedesktop
drwxrwxr-x 11 zhongyili admin 352 9 21 15:06 share
drwxr-xr-x 3 zhongyili admin 96 10 23 2018 var
再执行brew link
➜ ~ brew link python
Linking /usr/local/Cellar/python/3.7.5... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
➜ ~ brew link python
Linking /usr/local/Cellar/python/3.7.5... 1 symlinks created
现在python3安装完成了,我们看看版本对不对
➜ ~ python --version
Python 2.7.16
发现还是2.7,这是因为我们用的命令不对,得用python3。需要说明的是brew安装后,我们是不用自己配置环境变量的,brew自动在/usr/local/bin给我们建立的软链接。
如果python3 版本还不对,说明安装过程中有错,卸载了重新安装一遍
➜ ~ python3 -V
Python 3.7.5
zsh切换bash bash切换zsh
Python3 安装 报错 Error: An unexpected error occurred during the brew link
step 解决办法
Mac 上安装python3——手把手教程
2018-05-29 Mac下安装Python3出现Error: An unexpected error occurred during the brew link
step The for…
Python各版本的差异总结
Linux whoami命令
linux权限详细介绍