当前位置:   article > 正文

macOS自带Python2.7版本升级_pyenv python 2.7.18 mac

pyenv python 2.7.18 mac

为什么要升级

Mac自带的2.7版本将于2020年停止支持
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.

下载和安装

1、官网下载Python安装包

  • 下载地址:https://www.python.org/downloads/
  • 选择自己系统适合的pkg包下载,完成后点击安装
  • 安装完成后,默认安装路径为:/Library/Frameworks/Python.framework/Versions/3.9

2、使用brew安装

  • 安装brew

确保已经安装Xcode(或者Xcode命令行工具CommandLineTools)

  • 安装Python3.x

brew search python
brew install python3.x
第一行命令查看并选择python版本,看好要安装的版本,再使用第二行命令安装即可。

查看Python版本

python -V

神奇的事情发生了,你发现你的py版本还是2.7,这是因为python默认多版本可共存机制,而macOS默认版本指向的是原装的2.7版本。

将3.x版本设置为默认版本

查看不同安装方式的3.x安装地址

来源python安装路径
系统默认/System/Library/Frameworks/Python.framework/Versions/2.7
brew安装/usr/local/Cellar
官网pkg安装/Library/Frameworks/Python.framework/Versions/2.7

修改profile文件

  • 在terminal里运行open ~/.bash_profile打开~/.bash_profile
  • 修改文件
# Setting PATH for Python 3.9
# The original version is saved in .bash_profile.pysave
PATH="/usr/local/Cellar/python@3.9/3.9.4/bin:${PATH}"
export PATH
alias python="/usr/local/Cellar/python@3.9/3.9.4/bin/python3.9"
  • 1
  • 2
  • 3
  • 4
  • 5

【一般情况下,在安装py3.x版本后系统会自动生成bash_profile文件,但是我在修改bash_profile文件时,发现并没有bash_profile文件存在,于是touch了一个新的文件,并进行了修改后续操作】

  • source .bash_profile更新文件

**【经过一番折腾】**重新查看Python版本,发现版本已更新

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号