python - 如何让 Mac OS 使用 Homebrew 安装的 python

标签 python macos python-2.7

为了这个问题我在网上搜索了一段时间,目前我所做的是

  1. 在自制软件中安装了python32

  2. 更改了我的 .bash_profile 并在其中添加了以下行:

export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH

但是当我关闭终端并重新开始时,我输入'which python',它仍然打印:

/usr/bin/python

然后输入 'python --version' 仍然得到:

Python 2.7.2

我还尝试了以下说明:

brew link --overwrite python

或尝试通过运行以下指令来删除由 homebrew 安装的 python:

brew remove python

但是以上两条指令都会导致这个错误:

Error: No such keg: /usr/local/Cellar/python

谁能帮忙,谢谢

最佳答案

brew install pythonbrew info python 输出提及:

Unversioned symlinks python, python-config, pip etc. pointing to python3, python3-config, pip3 etc., respectively, have been installed into /opt/homebrew/opt/python@3.9/libexec/bin

这样跑

% echo 'export PATH=/opt/homebrew/opt/python@3.9/libexec/bin:$PATH' >> ~/.zprofile
% source ~/.zprofile
# For bash use ~/.bash_profile.

为您提供 Homebrew 创建的符号链接(symbolic link) - python=python3、pip=pip3 等

% python --version
Python 3.9.10
% pip --version
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)

关于python - 如何让 Mac OS 使用 Homebrew 安装的 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18419500/

相关文章:

python - 从对中创建 pandas 数据框的快速方法

python - Odoo - 防止按钮关闭向导

android - 找不到库 "libmaliinstr.so"

python - 如何打印 float 的全精度 [Python]

python - 如何在 .txt 文件中的所有字符之间添加空格

python - 正则表达式查找文本文件中字符串的所有出现位置。如何?

python - TensorFlow 队列馈送顺序

javac:无效的目标版本:执行 Maven 命令时在 Mac 上为 1.8

macos - Int32 无法转换为 gcl_queue_flags

python - 将 python 中的字符串替换为字母表序列