【发布时间】:2021-11-03 15:35:16
【问题描述】:
我使用 brew 安装了 python3。这是我第一次使用终端并为此使用 brew,我不确定我哪里出错了。按照另一个网站的建议安装后,我使用 Pyenv 更新 python 的版本并将最新版本设为全局版本。但每次我在终端输入 Python 时它显示 Python 2.7
% python
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Jun 18 2021, 03:23:52)
[GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy on darwin
Type "help", "copyright", "credits" or "license" for more information.
酿造信息如下。
% brew info python3
python@3.9: stable 3.9.7 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/python@3.9.rb
License: Python-2.0
==> Dependencies
Build: pkg-config ✔
Required: gdbm ✘, mpdecimal ✘, openssl@1.1 ✔, readline ✔, sqlite ✘, xz ✘
==> Caveats
Python has been installed as
/opt/homebrew/bin/python3
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
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/opt/homebrew/lib/python3.9/site-packages
tkinter is no longer included with this formula, but it is available separately:
brew install python-tk@3.9
See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 448,214 (30 days), 1,500,839 (90 days), 7,290,725 (365 days)
install-on-request: 157,960 (30 days), 522,744 (90 days), 2,279,934 (365 days)
build-error: 0 (30 days)'
未安装的部分让我感到困惑,但是当我使用 Pyenv 版本时,它显示在下面。
% pyenv versions
system
* 3.9.7 (set by /Users/ronabraham/.pyenv/version)`
我还将以下内容粘贴到我的 .zshrc 文件中。
export PYENV_ROOT="$HOME/.pyenv export PATH="$PYENV_ROOT/bin:$PATH if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)" fi
即使在此之后,Python 命令仍然返回 Python 2.7。
我再次从官方 python 下载链接安装了 Python 3.9.7。并尝试卸载 Brew Python 结果如下。
% brew uninstall python3
Error: No available formula or cask with the name "python3". Did you mean python@3.7, python@3.9, python@3.8, ipython, bpython, jython or cython?`
brew uninstall python@3.9
Error: No available formula or cask with the name "python@3.9". Did you mean python@3.9, python-tk@3.9, python@3.8, python@3.7 or python-yq?
这 2 个 Python(brew python 3.9.7 和 pkg installed 3.9.7 会导致问题吗?)如何删除 brew 版本或修复它并使其成为默认版本。
【问题讨论】:
标签: python-3.x macos homebrew