【发布时间】:2021-01-10 16:58:06
【问题描述】:
我使用命令pip3 install --upgrade pip升级了pip;然后,在终端窗口中打印了以下内容:
DEPRECATION: Python 3.5 reached the end of its life on September 13th,
2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021.
pip 21.0 will remove support for this functionality.
在线搜索有关在 mac 上升级 python 的正确方法将我引向两个来源 (1) 和 (2)。第二个来源提到修改.profile 和bash 脚本;尽管这些堆栈交换论坛(如this 和that)上的类似问题提供了一些帮助,但这些都是我难以理解的事情。但是,使用第一个来源的建议,我想我已经确定了一个潜在的未来问题(我读了 virtual venv 可能是一个很好的解决方案)。具体来说,
$ which python
/usr/bin/python
$ which python3
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
$ brew info python
python@3.8: stable 3.8.5 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python@3.8/3.8.5 (4,331 files, 66.8MB)
Poured from bottle on 2020-09-23 at 04:16:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/python@3.8.rb
License: Python-2.0
==> Dependencies
Build: pkg-config ✔
Required: gdbm ✔, openssl@1.1 ✔, readline ✔, sqlite ✔, xz ✔
==> Caveats
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.8/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.8/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 435,972 (30 days), 1,606,776 (90 days), 3,198,770 (365 days)
install-on-request: 158,335 (30 days), 466,841 (90 days), 519,965 (365 days)
build-error: 0 (30 days)
我认为这意味着我的 mac 上安装了 python 2、python 3.5 和 python 3.8。我尝试使用以下命令的多个版本(即python、python3、python3.8 等)升级我的 python 版本:
$ pip3 install --upgrade python
ERROR: Could not find a version that satisfies the requirement python (from versions: none)
ERROR: No matching distribution found for python
我已经安装了 python 3.8,但我显然运行的是 3.5;如何升级我的python版本?我该如何“清理这个烂摊子”?如果相关,我正在运行 macOS High Sierra 10.13.6,我喜欢/使用的唯一文本编辑器是 Atom(请不要对 vim 提出建议)。
编辑#1:
关注the steps from this post后,在TextEdit中打开了以下内容。
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
我注意到它在顶部写着Python 3.5。我是否用PATH=/usr/local/bin 覆盖给定路径PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"?我想运行 python 3.8;这会做我想要的吗?
编辑 #2:
按照编辑后的答案中的建议,在终端中运行 grep PATH $HOME/.* 在终端窗口中输出以下内容:
grep: /Users/username/.bash_sessions: Is a directory
grep: /Users/username/.cache: Is a directory
grep: /Users/username/.config: Is a directory
grep: /Users/username/.cups: Is a directory
grep: /Users/username/.git: Is a directory
grep: /Users/username/.idlerc: Is a directory
grep: /Users/username/.lightkurve-cache: Is a directory
grep: /Users/username/.local: Is a directory
grep: /Users/username/.matplotlib: Is a directory
grep: /Users/username/.npm: Is a directory
grep: /Users/username/.nvm: Is a directory
grep: /Users/username/.oracle_jre_usage: Is a directory
grep: /Users/username/.ssh: Is a directory
grep: /Users/username/.subversion: Is a directory
grep: /Users/username/.vnc: Is a directory
所以,我搜索包含 python 3.5 的目录。如果我在ls 而在/Users/username/Library/ 中,则Frameworks 未列出,所以我在其他地方搜索。但这让我很担心,因为我看到了PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"(来自编辑#1)。
$ pwd
/Users/username
$ cd .local/
$ ls
share
$ cd share
$ ls
virtualenvs
$ cd virtualenvs
$ ls
PyCodes-_a3khG54
$ cd PyCodes-_a3khG54
$ ls
bin include lib src
目录src 为空; include 包含 python3.5m 和 lib 包含 python3.5。
$ cd bin
$ ls
activate f2py python
activate.csh f2py3 python-config
activate.fish f2py3.5 python3
activate_this.py pip python3.5
easy_install pip3 wheel
easy_install-3.5 pip3.5
这里不应该有我可以编辑的文件吗?
【问题讨论】:
标签: python-3.x macos pip homebrew upgrade