Python3安装完全攻略 Mac篇

前言:mac系统自带,不过以当前mac系统的最新版本为例,自带的版本都是2.X版本,虽然不影响老版本项目的运行,但是最新的3.X版本的一些语法与2.X版本并不相同,网上的教程大神们也肯定都更新出了最新版的教程,我们不论是学习还是使用,当然用最新版会更好一点 。
我的电脑是 Air,系统版本是最新的macOS10.15.1
一、熟悉系统自带的
在安装最新版.X之前,我们先熟悉一下系统自带的 。
打开终端,输入:
$ python
WARNING: Python 2.7 is not recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS will not include Python 2.7. Instead, it is recommended that you transition to using 'python3' from within Terminal.Python 2.7.16 (default, Oct 17 2019, 17:14:30) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwinType "help", "copyright", "credits" or "license" for more information.
翻译下前面三句话:
这个版本包含在macOS中,以便与遗留软件兼容 。
macOS的未来版本将不包括 2.7 。
相反,建议您从终端内部过渡到使用’’ 。
二、开始安装 1、安装
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"==> This script will install:/usr/local/bin/brew/usr/local/share/doc/homebrew/usr/local/share/man/man1/brew.1/usr/local/share/zsh/site-functions/_brew/usr/local/etc/bash_completion.d/brew/usr/local/Homebrew==> The following new directories will be created:/usr/local/Caskroom==> The Xcode Command Line Tools will be installed.
2、搜索的包
$ brew search python3Error: You have not agreed to the Xcode license. Please resolve this by running:sudo xcodebuild -license accept$ sudo xcodebuild -license acceptPassword:****
问题:
因为更新了XCODE还未来得及使用 。
解决:
打开Xcode 统一协议,输入密码,so easy!
再次搜索
$ brew search python3==> Searching local taps...python3==> Searching taps on GitHub...Error: GitHub The GitHub credentials in the macOS keychain may be invalid.Clear them with:printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain eraseOr create a personal access token:https://github.com/settings/tokens/new?scopes=gist,public_repo&description=Homebrewand then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token"
报错:
The GitHub credentials in the macOS keychain may be invalid
大体的意思就是说 在钥匙串中的凭证失效了,因为苹果在某些过程中是需要验证的,我们的钥匙串中保存了很多不同的证书和凭证,如果过期了,那么就要重新生成或者授权才可以继续使用 。
既然知道问题了,下面就是动手解决了,上面也提示了给你两种解决方法 。
方法一:
Clear them with:printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain erase
用上面的语句清理下就可以了 。
方法二:
方法二就没有去尝试了,只能简单的给大家介绍一下,而且方法二比方法一相对麻烦一些。
这个要自己去 上重新创建一个token,然后回到本地,重新设置下token
create a personal access token:https://github.com/settings/tokens/new?scopes=gist,public_repo&description=Homebrewand then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token"