栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

MacOS通过homebrew安装python 3.7方法

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

重启终端失效解决办法:

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,
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/354900.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号