Homebrew
假设你没有安装Homebrew
,那么就执行:
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”
安装Python
执行命令:
yutao@MacBook-Pro Homebrew % brew install Python
可以看到,最后报错了,原因就是我的Homnebrew,需要更新下:
执行命令:
cd "$(brew --repo)" && git fetch && git reset --hard origin/master && brew update
需要等待挺长时间,等它更新完。
然后再次执行brew install Python
然后我们会看到如下日志,日志省略了~
... ...
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python@3.11/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.11/site-packages
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@3.11
gdbm (`dbm.gnu`) is no longer included in this formula, but it is available separately:
brew install python-gdbm@3.11
`dbm.ndbm` changed database backends in Homebrew Python 3.11.
If you need to read a database from a previous Homebrew Python created via `dbm.ndbm`,
you'll need to read your database using the older version of Homebrew Python and convert to another format.
`dbm` still defaults to `dbm.gnu` when it is installed.
For more information about Homebrew and Python, see: https://docs.brew.sh/Homebrew-and-Python
分析1:
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python@3.11/libexec/bin
这句话的意思,就是,如果你想要命令 python
启动 python3 、命令pip
启动 pip3,你需要把 /usr/local/opt/python@3.11/libexec/bin
放在你的 PATH
的开头。
我的是:
在终端执行命令:vim ~/.bash_profile
添加:
export PATH="/usr/local/opt/python@3.11/libexec/bin:$PATH"
分析2:
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.11/site-packages
这句话的意思就是,在使用命令pip3
安装的包,存放的目录,在/usr/local/lib/python3.11/site-packages
中。
分析3:
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@3.11
gdbm (`dbm.gnu`) is no longer included in this formula, but it is available separately:
brew install python-gdbm@3.11
这句话的意思是,tkinter
不再包含在formula
中,但是可以独立使用它,brew install python-tk@3.11
。
同理gdbm
,也是一样的。
分析4:
If you need to read a database from a previous Homebrew Python created via `dbm.ndbm`,
you'll need to read your database using the older version of Homebrew Python and convert to another format.
`dbm` still defaults to `dbm.gnu` when it is installed.
# 机器翻译
`dbm.ndbm` 在 Homebrew Python 3.11 中更改了数据库后端。
如果您需要从之前通过 dbm.ndbm 创建的 Homebrew Python 读取数据库,
您需要使用旧版本的 Homebrew Python 读取您的数据库并转换为另一种格式。
`dbm` 在安装时仍然默认为 `dbm.gnu`。
总结
为了更好的管理,最好使用 Homebrew来安装,也就是执行brew install Python
参考地址:
How to Update Python on Mac Terminal