MacOS通过homebrew安装python 3.7方法

显示Mac系统隐藏文件:

显示
defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder
隐藏
defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder

安装homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

查看homebrew是否安装成功:

brew -v

安装前先搜索一下是否已经存在python3的包:

brew search python3

已经存在,我们可以直接安装了:

brew install python@3.7

手动执行一下安装时未完成的创建连接:

brew link python@3.7

当前系统下的python3.7的信息:

brew info python@3.7

查询软件安装位置:

which python3

Mac当前系统的默认版本修改为3.7.12版本:

vi ~/.bash_profile
 
i键进入编辑模式
 
#添加配置信息
export PATH=$PATH:/usr/local/Cellar/python@3.7/3.7.12_1/bin:
alias python="/usr/local/Cellar/python@3.7/3.7.12_1/bin/python3.7"
 
Esc退出后编辑输入:wq保存
 
#编译系统配置文件
source ~/.bash_profile

=====也可以这样
alias ll='ls -la'
alias python="/opt/homebrew/bin/python3"

重启终端失效解决办法:

vi ~/.zshrc
 
i键进入编辑模式
 
#增加一行
source ~/.bash_profile
 
Esc退出后编辑输入:wq保存

在终端输入python -V后:

结束!~

题外话:

使用Visual Studio Code的Code Runner插件可能还会存在执行代码使用python2.7的问题,附上我自己的设置参数,如果你也碰到这个问题用我的配置参数就可以了。

{
    "update.mode": "manual",
    "extensions.autoUpdate": false,
    "editor.fontSize": 16,
    "code-runner.fileDirectoryAsCwd": true,
    "python.pythonPath": "/usr/local/bin/python3",
    "python.formatting.provider": "yapf",
    "code-runner.runInTerminal": true,
    "code-runner.executorMap": {
    	"python": "python -u"
    },
    "python.autoComplete.addBrackets": true,
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "workbench.startupEditor": "newUntitledFile",
    "python.defaultInterpreterPath": "/usr/local/bin/python3",
    "python.analysis.completeFunctionParens": true,
}
  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

福星M高照

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值