Pau*_*ine 58 python macos homebrew python-2.x
我在使用 brew 时遇到了 openssl 和 python@2 问题,这里已经解释了(未解决)。重新安装 Python 和 openssl 的文档化解决方法不起作用,所以我决定卸载并重新安装 Python。
问题是,当您尝试使用 brew 安装 Python 2 时,您会收到以下消息:
brew install python@2
Error: No available formula with the name "python@2"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow
python@2 was deleted from homebrew/core in commit 028f11f9e:
python@2: delete (https://github.com/Homebrew/homebrew-core/issues/49796)
EOL 1 January 2020.
We gave it 1 month more to live so that people had time to migrate.
All in all, developers had 11 years to do their migration.
You can use the `brew extract` command and maintain python@2 in your own
tap if necessary:
https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap
To show the formula before removal run:
git -C "$(brew --repo homebrew/core)" show 028f11f9e^:Formula/python@2.rb
If you still use this formula consider creating your own tap:
https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap
Run Code Online (Sandbox Code Playgroud)
不幸的是,我仍然有许多依赖于 Brew 的 python@2 的 brew 公式。那些包括awscli, letsencrypt, prsshuttle例如
aws
zsh: /usr/local/bin/aws: bad interpreter: /usr/local/opt/python@2/bin/python2.7: no such file or directory
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用brew extract他们记录的这个命令来重新安装 Python@2。它需要一个公式和一个水龙头。我想公式是python@2. 我不确定水龙头需要什么。
此外,重新安装水龙头,例如aws或letsencrypt也不能很好地工作。
重新安装awscli( brew reinstall awscli) 后,运行 aws 命令仍然会出错。
aws
/usr/local/Cellar/awscli/2.0.0/libexec/lib/python3.8/site-packages/jmespath/visitor.py:32: SyntaxWarning: "is" with a literal. Did you mean "=="?
if x is 0 or x is 1:
/usr/local/Cellar/awscli/2.0.0/libexec/lib/python3.8/site-packages/jmespath/visitor.py:32: SyntaxWarning: "is" with a literal. Did you mean "=="?
if x is 0 or x is 1:
/usr/local/Cellar/awscli/2.0.0/libexec/lib/python3.8/site-packages/jmespath/visitor.py:34: SyntaxWarning: "is" with a literal. Did you mean "=="?
elif y is 0 or y is 1:
/usr/local/Cellar/awscli/2.0.0/libexec/lib/python3.8/site-packages/jmespath/visitor.py:34: SyntaxWarning: "is" with a literal. Did you mean "=="?
elif y is 0 or y is 1:
/usr/local/Cellar/awscli/2.0.0/libexec/lib/python3.8/site-packages/jmespath/visitor.py:260: SyntaxWarning: "is" with a literal. Did you mean "=="?
if original_result is 0:
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: the following arguments are required: command
Run Code Online (Sandbox Code Playgroud)
hyp*_*not 158
似乎自制软件的工作人员真的尽可能地在 macOS 上使用 Python 2.7 变得尽可能困难。
brew extract链接真的没有帮助,您需要在此处寻找有关如何从提取的源中制作自己的水龙头的答案。brew extract命令甚至无法正常工作。解决方案非常简单,您只需要下载最新的已知提交并从该文件安装:
cd ~
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/86a44a0a552c673a05f11018459c9f5faae3becc/Formula/python@2.rb
brew install python@2.rb
rm python@2.rb
Run Code Online (Sandbox Code Playgroud)
可能会有关于“不稳定”的警告,我不明白这是因为 Git 历史记录中的提交尽可能稳定。
y3s*_*3sh 122
对于Apple 在 macOS 12.3 中删除系统 python 后出现在这里的用户,以下是如何安装和运行 python2 和 python3。
蟒蛇2
python, python2-> 蟒蛇 2.7
# Download/run the legacy macOS installer (pick which one for your sys)
https://www.python.org/downloads/release/python-2718/
# Add pip for python2.7
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip2.py
python2 get-pip2.py
# Optionally check for pip updates (in case of post-eol patches)
python2 -m pip install --upgrade pip
# Optionally add the helpers like easy_install back onto your path
# In your ~/.zprofile or whatever bash/shell profile equivalent
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# Optionally add some helpers while editing shell profile
alias pip2="python2 -m pip"
alias venv2="virtualenv -p python2"
alias venv3="virtualenv -p python3"
# Optionally some apple-specific std libraries are missing, search
# and download them. Example: plistlib.py
curl https://raw.githubusercontent.com/python/cpython/2.7/Lib/plistlib.py -o /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py
# Lastly, there is no symlink /usr/bin/python anymore
# /usr/bin is system protected so you can't add one either
#
# Change your programs to use /usr/local/bin/python
# or google how to disable macOS SIP to make a symlink in /usr/bin
Run Code Online (Sandbox Code Playgroud)
蟒蛇3
python3-> 蟒蛇3
brew update
brew install python3
# Add pip for python 3 in case it is missing
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
# Check for pip updates
python3 -m pip install --upgrade pip
# Optionally add a helper in ~/.zprofile
alias venv3="virtualenv -p python3"
Run Code Online (Sandbox Code Playgroud)
测试一下
~ % python --version
Python 2.7.18
~ % python2 --version
Python 2.7.18
~ % python3 --version
Python 3.9.10
# Running older python2
python2 -m pip install...
python2 ...
# Testing the venv2 alias from above
venv2 foo
source foo/bin/activate
pip -V # pip 20... from... python2.7
pip install -y -r req.txt
pip uninstall -y -r req.txt
pip freeze
deactivate
# Testing the venv3 alias from above
venv3 foo3
source foo3/bin/activate
pip -V # pip22... from ...python3.9
pip install -y -r req.txt
pip uninstall -y -r req.txt
pip freeze
deactivate
Run Code Online (Sandbox Code Playgroud)
通过卸载/重新安装进行故障排除
# Credit to https://www.macupdate.com/app/mac/5880/python/uninstall
# for many of the tips in this section.
# Sometimes there are problems related to accepting xcode
# tool agreement. Open XCode to make sure it finished
# installing its tool updates.
# Remove old python Application installs
# open the apps dir and delete Python 2, 3 via Finder
open /Applications
# Remove old brew installs
brew list | grep python
brew uninstall python
brew uninstall python3
# find/remove lingering unlinked kegs
ls /usr/local/Cellar/ | grep python
# Cleanup binaries
sudo rm -rf /Library/Frameworks/Pyth*
rm /usr/local/bin/pip*
# Cleanup symlinks
which -a python # check results, and rm each one
which -a python2 # check results, and rm each one
which -a python3 # check results, and rm each one
brew cleanup # prunes symlinks
Run Code Online (Sandbox Code Playgroud)
jvf*_*jvf 50
python@2从本地水龙头安装以下方法适用于 的当前版本 ( c9b8a3ef6) brew:
$ brew tap-new <user>/homebrew-python2
$ brew extract python@2 <user>/homebrew-python2
$ brew install /usr/local/Homebrew/Library/Taps/<user>/homebrew-python2/Formula/python@2.7.17.rb
Run Code Online (Sandbox Code Playgroud)
该brew tap-new命令在/usr/local/Homebrew/Library/Taps/<user>/homebrew-python2. 水龙头名称需要一个<user>和一个<repo>由 分隔的组件/。实际值是任意的。上面的命名遵循如何创建和维护 Tap 中的约定。如果您想将点击推送到 GitHub,您可以使用您的 GitHub 用户名作为用户。没有必要推送到 GitHub(并且没有在上面的说明中执行)。
这些brew extract命令从 repos 历史中提取最新版本的公式到给定的(本地)tap 中。在我们的情况下python@2.7.17.rb被提取。
该brew install命令最终会安装公式。
上面讨论的方法(从 GitHub 提交 URL 安装旧版本的公式)不再适用python@2于brew( c9b8a3ef6)的当前版本,它会产生以下错误:
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/86a44a0a552c673a05f11018459c9f5faae3becc/Formula/python@2.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from 88f17b8b6 to c9b8a3ef6.
...
Error: Calling Installation of python@2 from a GitHub commit URL is disabled! Use 'brew extract python@2' to stable tap on GitHub instead.
Run Code Online (Sandbox Code Playgroud)
小智 11
请检查以下命令(我在 macOS 10.13 上使用它,对于较新的 macOS,它可能无需源代码编译即可运行):
brew install pr0d1r2/python2/python@2.7.17 --build-from-source
Run Code Online (Sandbox Code Playgroud)
您可以使用以下pyenv命令安装 python:
brew install pyenv
pyenv install 2.7.18
Run Code Online (Sandbox Code Playgroud)
(可选)将其设置为您的全局默认值:
pyenv global 2.7.18
Run Code Online (Sandbox Code Playgroud)
关于为什么使用pyenv比brew用于管理您的 python 安装更好的好文章。
对于后代,在 macOS 10.15(2021 年 5 月)上工作:
/usr/local/bin/brew tap-new ${USER}/homebrew-python2
/usr/local/bin/brew extract python@2 ${USER}/homebrew-python2
/usr/local/bin/brew install /usr/local/Homebrew/Library/Taps/${USER}/homebrew-python2/Formula/python@2.7.17.rb
# https://github.com/Homebrew/brew/issues/5734#issuecomment-464705002
/usr/local/bin/brew untap ${USER}/python2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49308 次 |
| 最近记录: |