显示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,
}
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐