转载请注明 来源:http://www.eword.name/
Author:eword
Email:[email protected]
安装Python
一、查询是否安装了Python及安装路径
#查看当前Python版本
python --version
Python 2.7.16
#查看当前所有Python版本路径
appledeMBP:~ apple$ which python2.7
/usr/local/bin/python2.7
appledeMBP:~ apple$ which python3.5
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
appledeMBP:~ apple$ which python3.7
/usr/local/bin/python3.7
appledeMBP:~ apple$ which python
/usr/local/bin/python
appledeMBP:~ apple$ which python3
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
appledeMBP:~ apple$ which python2
/usr/local/bin/python2
查看pip2版本
appledeMBP:~ apple$ pip2 --version
pip 18.0 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
查看pip3版本
appledeMBP:~ apple$ pip3 --version
pip 18.1 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip (python 3.5)
二、Mac OS 安装Pythne 3.x
Python 官方下载地址:
https://www.python.org/downloads/
macOS 64-bit installer 即为 Mac OS X 系统的 Python 安装包。这里下载 3.8.1这个版本,得到python-3.8.1-macosx10.9.pkg 安装包。
双击 python-3.8.1-macosx10.9.pkg 就进入了 Python 安装向导,然后按照向导一步一步向下安装,一切保持默认即可。
三、验证安装结果
安装完成以后,你的 Mac OS X 上将同时存在 Python 3.x 和 Python 2.x 的运行环境,在终端(Terminal)输入python
命令将进入 Python 2.x 开发环境,在终端(Terminal)输入python3
命令将进入 Python 3.x 开发环境。
appledeMBP:~ apple$ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
四、卸载Python
如果有别的不需要的版本可以卸载,例如卸载3.6,安装3.7
4.1 删除Python 3.6 framework
appledeMBP:~ apple$ sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.6
4.2 删除Python 3.6 应用目录
appledeMBP:~ apple$ sudo rm -rf "/Applications/Python 3.6"
4.3 删除/usr/local/bin 目录下指向的Python3.6的连接
appledeMBP:~ apple$ cd /usr/local/bin/
appledeMBP:~ apple$ ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/3.6' | awk '{print $9}' | tr -d @ | xargs rm
五、添加软链接
# 查看pip3 安装地址
appledeMBP:~ which pip3
/usr/bin/pip3
# 创建软链接
appledeMBP:~ ln -s /usr/bin/pip3 /usr/local/bin/pip
# 查看python3 安装地址
appledeMBP:~ which python3
/usr/bin/python3
# 创建软链接
appledeMBP:~ ln -s /usr/bin/python3 /usr/local/bin/python
备注
Mac OS 下的 Python 3.x 自带 IDLE 简易开发工具,我们可以在程序列表中找到它。
标签:bin,apple,Python,python,usr,appledeMBP,安装 From: https://www.cnblogs.com/shylock/p/pythonmac202008201.html