一,准备工作:
1,macos上默认的python版本还是2.7
我们选择从官网下载最新的3.9.1安装
2, python官网
https://www.python.org/downloads/
二,下载安装程序后运行:
一步步进行,直到安装完成
三,替换系统默认自带的python2.7
说明:我的shell使用的是zsh,大家根据自己的情况处理
修改.zprofile
liuhongdi@liuhongdideMacBook-Pro ~ % vi .zprofile
输入内容:
# Setting PATH for Python 3.9 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}" export PATH export PATH="/usr/local/opt/python@3.9/bin:$PATH" alias python="/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9" alias pip="/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9”
使生效:
liuhongdi@liuhongdideMacBook-Pro ~ % source .zprofile
查看效果:
liuhongdi@liuhongdideMacBook-Pro ~ % python --version Python 3.9.1
已生效
四,写一个helloworld代码测试一下:
liuhongdi@liuhongdideMacBook-Pro chapt_01 % vi helloworld.py
内容:
print("hello world!")
测试:
liuhongdi@liuhongdideMacBook-Pro chapt_01 % python helloworld.py hello world!
说明:刘宏缔的架构森林—专注it技术的博客,
网址:https://imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/05/26/macos-big-sur-11-1-an-zhuang-python3-python-3-9-1/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com